You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2009/02/22 05:17:58 UTC
svn commit: r746631 [1/3] - in /incubator/etch/branches/name-service: ./
services/ services/ns/ services/ns/src/ services/ns/src/main/
services/ns/src/main/etch/ services/ns/src/main/java/
services/ns/src/main/java/etch/ services/ns/src/main/java/etch/...
Author: sccomer
Date: Sun Feb 22 04:17:56 2009
New Revision: 746631
URL: http://svn.apache.org/viewvc?rev=746631&view=rev
Log:
initial name service prototype.
Added:
incubator/etch/branches/name-service/services/
incubator/etch/branches/name-service/services/ns/
incubator/etch/branches/name-service/services/ns/src/
incubator/etch/branches/name-service/services/ns/src/main/
incubator/etch/branches/name-service/services/ns/src/main/etch/
incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/
incubator/etch/branches/name-service/services/ns/src/main/java/etch/
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java (with props)
incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java (with props)
incubator/etch/branches/name-service/services/ns/src/test/
incubator/etch/branches/name-service/services/ns/src/test/java/
incubator/etch/branches/name-service/services/ns/src/test/java/etch/
incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/
incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/
incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/
incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java (with props)
incubator/etch/branches/name-service/services/ns/target/
incubator/etch/branches/name-service/services/ns/target/generated-sources/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceHelper.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceServer.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/RemoteNameService.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/RemoteNameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/RemoteNameServiceServer.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/StubNameService.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/StubNameServiceClient.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/StubNameServiceServer.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/ValueFactoryNameService.java (with props)
incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/readme-etch-java-files.txt (with props)
Modified:
incubator/etch/branches/name-service/.classpath
Modified: incubator/etch/branches/name-service/.classpath
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/.classpath?rev=746631&r1=746630&r2=746631&view=diff
==============================================================================
--- incubator/etch/branches/name-service/.classpath (original)
+++ incubator/etch/branches/name-service/.classpath Sun Feb 22 04:17:56 2009
@@ -41,6 +41,8 @@
<classpathentry kind="src" path="binding-python/compiler/src/main/resources"/>
<classpathentry kind="src" path="interoptester/src/main/java"/>
<classpathentry kind="src" path="interoptester/src/test/java"/>
+ <classpathentry kind="src" path="services/ns/src/main/java"/>
+ <classpathentry kind="src" path="services/ns/target/generated-sources/main/etch/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ETCH_DEPENDENT_JARS"/>
<classpathentry kind="output" path="bin"/>
Added: incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch Sun Feb 22 04:17:56 2009
@@ -0,0 +1,303 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+module etch.services.ns
+
+/**
+ * The NameService provides translation from an abstract name for a service to a
+ * uri that may be used to contact the service. A given service may offer
+ * several different connection schemes, and a client may only support a subset
+ * of those. So, when a client wishes to connect to a service, it may query
+ * the NameService with both abstract name and desired schemes in order to find
+ * a suitable match.
+ *
+ * Some example queries:
+ *
+ * All services with servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * sourceUri='Foo/bar/tcp'
+ *
+ * Same as the query above, but written out longhand:
+ *
+ * servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * Fully qualified sourceUri:
+ *
+ * sourceUri='Foo/bar/tcp/1'
+ *
+ * Any instance of service Foo located in Austin, TX:
+ *
+ * servicename='Foo' and qualities.location='Austin, TX'
+ *
+ * Instances of service Foo with capacity >= 400:
+ *
+ * servicename='Foo' and qualities.capacity>=400
+ *
+ * Relative operations on qualities require that the quality be present and be
+ * comparable (with mixed types some type promotion is supported). But you might
+ * be surprised, qualities which are absent will give a negative comparison no
+ * matter which sense is used: both qualities.x > 50 and qualities.x < 50 are
+ * false whenever qualities.x is null. Consider this test: not qualities.x < 50.
+ * This is not the same as qualities.x >= 50. It is the same as qualities.x =
+ * null or qualities.x >= 50.
+ */
+@Timeout( 30000 )
+service NameService
+{
+ /** An entry describing a service. */
+ struct Entry
+ (
+ /** A service description uri, composed of
+ * servicename/instancename/qualifier[/priority]. */
+ string sourceUri,
+
+ /** Qualities of this service instance. */
+ Map qualities,
+
+ /** Etch service connection uri, for example
+ * tcp://localhost:9000?filter=KeepAlive */
+ string targetUri,
+
+ /** Lifetime in seconds from last update. */
+ int ttl,
+
+ /** Who created or last update. */
+ string who,
+
+ /** Date / time of create or last update. */
+ Datetime lastUpdate,
+
+ /** Flag indicating entry has been removed. */
+ boolean removed
+ )
+
+ /**
+ * Look up an entry by matching it against the sourceUri.
+ *
+ * @param source source uri
+ *
+ * @return entry matching the source uri. In the case of an
+ * absent instance name or qualifier, the implementation
+ * can decide which Entry to return.
+ */
+ @Authorize( canLookup, source )
+ Entry lookup( string source )
+
+ /**
+ * Looks up entries by matching them against the query string. Entries are
+ * returned in a stable and consistent order, increasing alphabetical by
+ * servicename, instancename, and scheme, and then increasing numerical by
+ * priority. If a scheme search term appears with a list, schemes are
+ * returned in the specified order (e.g., scheme='tls,tcp').
+ *
+ * @param query a sql-like query expression using the elements of the
+ * sourceUri, targetUri, and qualities. If query is null or the empty
+ * string, all entries are matched.
+ *
+ * @param offset offset in the list of matched items of the first item to
+ * return. This parameter and the count parameter are used to step through
+ * the result set when there are many results.
+ *
+ * @param count number of items to return.
+ *
+ * @return entries matching query. If you requested 10 items and 10 are
+ * returned, there could be more. To get the next batch, add results.length
+ * to offset and call find again:
+ *
+ * int i = 0;
+ * int n = 10;
+ * Entry[] results;
+ * while ((results = service.find( null, i, n )).length > 0)
+ * {
+ * for (Entry e: results)
+ * processEntry( e );
+ * if (results.length < n)
+ * break;
+ * i += results.length;
+ * }
+ */
+ @Authorize( canFind, query )
+ Entry[] find( string query, int offset, int count )
+
+ /**
+ * Adds or updates the specified entry. The given parameters replace any
+ * existing values in an Entry whose key is sourceUri, whereas who and
+ * lastUpdate are set to the current user and current date / time,
+ * respectively.
+ *
+ * @param sourceUri the uri describing the service. The uri should be of
+ * the form "servicename/instancename/scheme[/priority]", where servicename
+ * is a valid fully qualified service name (e.g.,
+ * etch.services.ns.NameService"), instancename is a valid etch identifier
+ * (e.g, fred, alice01), scheme is a valid uri scheme (e.g., tcp, tls), and
+ * priority is an integer >= 1. If priority is omitted, it is defaulted to
+ * 1.
+ *
+ * @param qualities a map which may be used to describe additional features
+ * of the entry, such as purpose, licenses, capacity, location, owner,
+ * whatever. Query strings may test values of qualities using a variety of
+ * sql-like operators. Qualities may be null.
+ *
+ * @param targetUri the uri describing the contact information for the
+ * service.
+ *
+ * @param ttl the lifetime of the entry specified as seconds. 0 means
+ * forever, -1 means remove immediately when the connection to the
+ * NameService is dropped.
+ */
+ @Authorize( canRegister, sourceUri, qualities, targetUri )
+ void register( string sourceUri, Map qualities, string targetUri, int ttl )
+
+ /**
+ * Registers a number of entries all in one operation. Identical to calling
+ * register with each entry in turn.
+ *
+ * @param entries a sequence of Entry records with sourceUri, targetUri,
+ * qualities, and ttl as specified in register() above. Who and lastUpdate
+ * fields are ignored.
+ */
+ @Authorize( canRegisterBulk, entries )
+ void registerBulk( Entry[] entries )
+
+ /**
+ * Removes the specified entry.
+ *
+ * @param sourceUri the uri describing the service.
+ */
+ @Authorize( canUnregister, sourceUri, deleteEntry )
+ void unregister( string sourceUri, boolean deleteEntry )
+
+ /**
+ * Adds a request for notification of changes to entries matching the query.
+ * The current value of all matching entries is delivered via entryChanged
+ * client message, as well as any updates or new entries.
+ *
+ * @param query a sql-like query expression using the elements of the
+ * sourceUri, targetUri, and qualities. If query is null or the empty
+ * string, all entries are matched.
+ */
+ @Authorize( canFind, query )
+ void subscribe( string query )
+
+ /**
+ * Removes a request for notification of changes to entries matching the
+ * query.
+ *
+ * @param query a query previously passed to subscribe. The string must
+ * match exactly.
+ */
+ void unsubscribe( string query )
+
+ /**
+ * Removes all requests for notification of changes to entries. This
+ * operation is implicitly performed when the connection to the NameService
+ * is dropped.
+ */
+ void unsubscribeAll()
+
+ ////////////////////
+ // RIGHTS TESTING //
+ ////////////////////
+
+ /**
+ * Tests whether the current user is authorized to lookup the source.
+ * @param source the complete specification api/instance/scheme.
+ */
+ boolean canLookup( string source )
+
+ /**
+ * Tests whether the current user is authorized to run the query.
+ *
+ * @param query a sql-like query expression using the elements of the
+ * sourceUri, targetUri, and qualities. If query is null or the empty
+ * string, all entries are matched.
+ *
+ * @return true if the current user is authorized to run the query.
+ */
+ boolean canFind( string query )
+
+ /**
+ * Tests whether the current user is authorized to register the service.
+ *
+ * @param sourceUri the uri describing the service.
+ *
+ * @param qualities a map which may be used to describe additional features
+ * of the entry.
+ *
+ * @param targetUri the actual uri of the service
+ *
+ * @return true if the current user is authorized to register the service.
+ */
+ boolean canRegister( string sourceUri, Map qualities, string targetUri )
+
+ /**
+ * Tests whether the current user is authorized to unregister the service.
+ *
+ * @param sourceUri the uri describing the service.
+ *
+ * @param deleteEntry if true, the entire entry matching the sourceUri
+ * would be deleted. if false, only the target uri matching the sourceUri
+ * would be deleted, but the entry would be intact.
+ *
+ * @return true if the current user is authorized to register the service.
+ */
+ boolean canUnregister( string sourceUri, boolean deleteEntry )
+
+
+ /**
+ * Tests whether the current user is authorized to register the entries.
+ * This is the same as:
+ *
+ * for (Entry entry: entries)
+ * if (!canRegister( entry.sourceUri, entry.qualities ))
+ * return false;
+ * return true;
+ *
+ * @param entries a sequence of Entry records with sourceUri, targetUri,
+ * qualities, and ttl as specified in register() above. Who and lastUpdate
+ * fields are ignored.
+ *
+ * @return true if the current user is authorized to register the entries.
+ * This is an all or nothing proposition.
+ */
+ boolean canRegisterBulk( Entry[] entries )
+
+ ////////////////////
+ // CLIENT METHODS //
+ ////////////////////
+
+ /**
+ * Notifies the client of a change in an entry. The entry might have been
+ * created, updated, or removed.
+ *
+ * Note: while this might have normally been an event, we made it a call
+ * to slow down the processing of what might otherwise be a rather large
+ * change set.
+ *
+ * Note: when keeping track of entries, always keep the one with the latest
+ * lastUpdate.
+ *
+ * @param query the query which triggered the notification.
+ *
+ * @param entry the entry which has changed.
+ */
+ @Direction( client )
+ void entryChanged( string query, Entry entry )
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/etch/ns.etch
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,65 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns;
+
+import java.net.ConnectException;
+
+/**
+ * Your custom implementation of BaseNameServiceClient. Add methods here to provide
+ * implementations of messages from the server.
+ */
+public class ImplNameServiceClient extends BaseNameServiceClient
+{
+ /**
+ * Constructs the ImplNameServiceClient.
+ *
+ * @param server a connection to the server session. Use this to send a
+ * message to the server.
+ */
+ public ImplNameServiceClient( RemoteNameServiceServer server )
+ {
+ this.server = server;
+ }
+
+ /**
+ * A connection to the server session. Use this to send a
+ * message to the server.
+ */
+ @SuppressWarnings( "unused" )
+ private final RemoteNameServiceServer server;
+
+ // TODO insert methods here to provide implementations of NameServiceClient
+ // messages from the server.
+
+ @Override
+ public void _sessionNotify( Object event ) throws Exception
+ {
+ if ( event instanceof ConnectException )
+ {
+ System.out.println("Service couldn't establish connection with the Name Service.");
+ }
+ else if (event instanceof Throwable)
+ ((Throwable) event).printStackTrace();
+
+ }
+
+
+}
\ No newline at end of file
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceClient.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,122 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Your custom implementation of BaseNameServiceServer. Add methods here to provide
+ * implementations of messages from the client.
+ */
+public class ImplNameServiceServer extends BaseNameServiceServer
+{
+ /**
+ * Constructs the ImplNameServiceServer.
+ *
+ * @param client a connection to the client session. Use this to send a
+ * message to the client.
+ */
+ public ImplNameServiceServer( RemoteNameServiceClient client )
+ {
+ this.client = client;
+ }
+
+ /**
+ * A connection to the client session. Use this to send a
+ * message to the client.
+ */
+ @SuppressWarnings( "unused" )
+ private final RemoteNameServiceClient client;
+
+ private static Map<String, Entry> nsEntries =
+ Collections.synchronizedMap( new HashMap<String, Entry>() );
+
+ @Override
+ public Boolean canRegister(String sourceUri, Map<?, ?> qualities,
+ String targetUri)
+ {
+ boolean canRegister = true;
+
+ // Logic for canRegister goes here
+
+ return canRegister;
+ }
+
+ @Override
+ public void register(String sourceUri, Map<?, ?> qualities,
+ String targetUri, Integer ttl)
+ {
+
+ Entry newEntry = new Entry( sourceUri, qualities, targetUri, ttl, null, new Date(), false );
+ nsEntries.put( sourceUri, newEntry );
+
+ printLookupTable();
+ }
+
+ @Override
+ public Boolean canLookup( String source )
+ {
+ boolean canLookup = true;
+
+ // Logic for canLookup
+
+ return canLookup;
+ }
+
+ @Override
+ public Entry lookup( String source )
+ {
+ return nsEntries.get( source );
+ }
+
+ @Override
+ public Boolean canUnregister( String sourceUri, Boolean deleteEntry )
+ {
+ boolean canUnregister = true;
+
+ // Logic for canUnregister
+
+ return canUnregister;
+ }
+
+ @Override
+ public void unregister( String sourceUri, Boolean deleteEntry )
+ {
+ if ( deleteEntry )
+ nsEntries.remove( sourceUri );
+ else
+ {
+ nsEntries.get( sourceUri ).targetUri = null;
+ nsEntries.get( sourceUri ).removed = true;
+ }
+ printLookupTable();
+ }
+
+ private void printLookupTable()
+ {
+ System.out.println("\nLookup Table: ");
+ System.out.println("---------------\n");
+ System.out.println(nsEntries.toString());
+ }
+}
\ No newline at end of file
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/ImplNameServiceServer.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,57 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns;
+
+/**
+ * Main program for NameServiceClient. This program makes a connection to the
+ * listener created by MainNameServiceListener.
+ */
+public class MainNameServiceClient implements NameServiceHelper.NameServiceClientFactory
+{
+ /**
+ * Main program for NameServiceClient.
+ *
+ * @param args command line arguments.
+ * @throws Exception
+ */
+ public static void main( String[] args ) throws Exception
+ {
+ // TODO Change to correct URI
+ String uri = "tcp://localhost:4001";
+
+ RemoteNameServiceServer server = NameServiceHelper.newServer( uri, null,
+ new MainNameServiceClient() );
+
+ // Connect to the service
+ server._startAndWaitUp( 4000 );
+
+ // TODO Insert Your Code Here
+
+ // Disconnect from the service
+ server._stopAndWaitDown( 4000 );
+ }
+
+ public NameServiceClient newNameServiceClient( RemoteNameServiceServer server )
+ throws Exception
+ {
+ return new ImplNameServiceClient( server );
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceClient.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,57 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns;
+
+import org.apache.etch.bindings.java.support.ServerFactory;
+import org.apache.etch.util.core.io.Transport;
+
+/**
+ * Main program for NameServiceServer. This program makes a listener to accept
+ * connections from MainNameServiceClient.
+ */
+public class MainNameServiceListener implements NameServiceHelper.NameServiceServerFactory
+{
+ /**
+ * Main program for NameServiceServer.
+ *
+ * @param args command line arguments.
+ * @throws Exception
+ */
+ public static void main( String[] args ) throws Exception
+ {
+ // TODO Change to correct URI
+ String uri = "tcp://0.0.0.0:8002";
+
+ ServerFactory listener = NameServiceHelper.newListener( uri, null,
+ new MainNameServiceListener() );
+
+ // Start the Listener
+ listener.transportControl( Transport.START_AND_WAIT_UP, 4000 );
+
+ System.out.println( "Naming service UP at : " + uri );
+ System.in.read();
+ }
+
+ public NameServiceServer newNameServiceServer( RemoteNameServiceClient client )
+ {
+ return new ImplNameServiceServer( client );
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/MainNameServiceListener.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,348 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns.support;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.etch.util.AlarmListener;
+import org.apache.etch.util.AlarmManager;
+import org.apache.etch.util.URL;
+import org.apache.etch.util.core.io.Session;
+
+import etch.services.ns.BaseNameServiceClient;
+import etch.services.ns.NameServiceClient;
+import etch.services.ns.NameServiceHelper;
+import etch.services.ns.RemoteNameServiceServer;
+import etch.services.ns.NameService.Entry;
+
+public class DefaultNSLib extends NSLib
+{
+ private final static int INITIAL_ALARM_DELAY = 1;
+
+ public NSLib getImplInstance()
+ {
+ return new DefaultNSLib();
+ }
+
+ /**
+ * Collection of <session, record> entries to keep track of all listeners connected
+ * to this instance of NSLib
+ */
+ public Map<Session, Record> recordsBySession = Collections.synchronizedMap(
+ new HashMap<Session, Record>() );
+
+ /*
+ * Map of <nsUri, RemoteNameServiceServer>
+ */
+ private Map<String, RemoteNameServiceServer> serversByNsUri =
+ new HashMap<String, RemoteNameServiceServer>();
+
+ /**
+ * Create a new RemoteNameServiceServer with the nsUri supplied
+ *
+ * @param nsUri uri of the target name service
+ * @return a new RemoteNameServiceServer
+ */
+ private static RemoteNameServiceServer createNewServer( String nsUri )
+ throws Exception
+ {
+ return NameServiceHelper.newServer( nsUri, null,
+ new NameServiceHelper.NameServiceClientFactory()
+ {
+ @Override
+ public NameServiceClient newNameServiceClient(
+ RemoteNameServiceServer server )
+ throws Exception
+ {
+ return new BaseNameServiceClient();
+ }
+ }
+ );
+ }
+
+ /**
+ * Starts this instance of the NSLib if it is not already started
+ */
+ private static void start( RemoteNameServiceServer server ) throws Exception
+ {
+ try
+ {
+ server._startAndWaitUp( 4000 );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ server._stop();
+ throw e;
+ }
+ }
+
+ /**
+ * Disconnect from the name service
+ */
+ private static void stop( RemoteNameServiceServer server ) throws Exception
+ {
+ try
+ {
+ server._stopAndWaitDown( 4000 );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ public RemoteNameServiceServer getServer( String nsUri ) throws Exception
+ {
+ synchronized( serversByNsUri )
+ {
+ if ( ! serversByNsUri.containsKey( nsUri ) )
+ {
+ RemoteNameServiceServer server = createNewServer( nsUri );
+ serversByNsUri.put( nsUri, server );
+ return server;
+ }
+ else
+ return serversByNsUri.get( nsUri );
+ }
+ }
+
+ /**
+ * Convenience object holding relevant listener data
+ */
+ private class Record implements AlarmListener
+ {
+ String nsUri;
+ String sourceUri;
+ Map<?,?> qualities;
+ String targetUri;
+ int ttl;
+
+ public Record( String nsUri, String sourceUri, Map<?,?> qualities, String targetUri, int ttl )
+ {
+ this.nsUri = ( nsUri == null || nsUri.isEmpty() )? defaultNsUri : nsUri;
+ this.sourceUri = sourceUri;
+ this.qualities = qualities;
+ this.targetUri = targetUri;
+ this.ttl = ttl;
+ }
+
+ @Override
+ public int wakeup( AlarmManager manager, Object state, long due )
+ {
+ try
+ {
+ register( this, state );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ return RECONNECT_DELAY;
+ }
+ }
+
+ public void register( Session session, String uri, Map<?,?> qualities, int ttl )
+ {
+ if ( session == null )
+ throw new IllegalArgumentException( "session == null" );
+
+ URL u = new URL( uri );
+
+ if ( ! u.hasTerm( EtchTransportFactory.LISTENER_REGISTERED_URI ) )
+ throw new IllegalArgumentException( "listener registered uri " +
+ "not configured properly within the etch uri" );
+
+ String sourceUri = u.getUri();
+ String targetUri = u.getTerm( EtchTransportFactory.LISTENER_REGISTERED_URI );
+ String nsUri = null;
+
+ if ( sourceUri == null || sourceUri.isEmpty() )
+ throw new IllegalArgumentException( "sourceUri == null" );
+
+ // extract if present in uri
+ if ( u.hasTerm( EtchTransportFactory.NS_URI ) )
+ nsUri = u.getTerm( EtchTransportFactory.NS_URI );
+
+ if ( nsUri == null || nsUri.isEmpty() )
+ nsUri = defaultNsUri;
+
+ Record record = new Record( nsUri, sourceUri, qualities, targetUri, ttl );
+ //Assertion.check( recordsBySession.containsKey( session ), "session already exists" );
+ recordsBySession.put( session, record );
+
+ // add register task to the alarm manager
+ AlarmManager.staticAdd( record, session, INITIAL_ALARM_DELAY );
+ }
+
+ /**
+ * Private method to actually register
+ * @param record
+ */
+
+ private void register( Record record, Object state ) throws Exception
+ {
+ if ( record == null )
+ throw new IllegalArgumentException( "record == null" );
+
+ try
+ {
+ RemoteNameServiceServer server = getServer( record.nsUri );
+ synchronized( server )
+ {
+ start( server ); // start the server
+
+ try
+ {
+ server.register( record.sourceUri, record.qualities, // register
+ record.targetUri, record.ttl );
+ }
+ catch( RuntimeException e )
+ {
+ System.out.println("Couldn't register with name service. " +
+ "Trying again after " + RECONNECT_DELAY + " seconds ..." );
+ ((Session)state).sessionNotify( e );
+ }
+ finally
+ {
+ stop( server ); // stop the server
+ }
+ }
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void unregister( Session session, String uri, boolean deleteEntry )
+ {
+ if ( session == null )
+ throw new IllegalArgumentException( "session == null" );
+
+ URL u = new URL( uri );
+
+ String sourceUri = u.getUri();
+ if ( sourceUri == null || sourceUri.isEmpty() )
+ throw new IllegalArgumentException( "sourceUri == null" );
+
+ String nsUri = null;
+ if ( u.hasTerm( EtchTransportFactory.NS_URI ) )
+ nsUri = u.getTerm( EtchTransportFactory.NS_URI );
+ if ( nsUri == null || nsUri.isEmpty() )
+ nsUri = getDefaultNsUri();
+
+ // remove alarm for that session/record
+ AlarmManager.staticRemove( recordsBySession.remove( session ) );
+
+ RemoteNameServiceServer server = serversByNsUri.get( nsUri );
+ try
+ {
+ synchronized ( server )
+ {
+ start( server );
+ try
+ {
+ server.unregister( sourceUri, deleteEntry );
+ }
+ finally
+ {
+ stop( server );
+ }
+ }
+ }
+ catch( Exception e )
+ {
+ try
+ {
+ session.sessionNotify( e );
+ }
+ catch( Exception e1 )
+ {
+ e1.printStackTrace();
+ }
+ }
+ }
+
+ public Entry lookup( String uri )
+ {
+ String nsUri = null;
+ URL u = new URL( uri );
+ if ( u.hasPort() )
+ nsUri = "tcp://" + u.getHost() + ":" + u.getPort();
+
+ String sourceUri = u.getUri();
+
+ if ( nsUri == null || nsUri.isEmpty() )
+ nsUri = getDefaultNsUri();
+
+ if ( sourceUri == null || sourceUri.isEmpty() )
+ throw new IllegalArgumentException( "sourceUri == null" );
+
+ Entry result = null;
+
+ try
+ {
+ RemoteNameServiceServer server = getServer( nsUri );
+ synchronized ( server )
+ {
+ start( server );
+
+ try
+ {
+ result = server.lookup( sourceUri );
+ }
+ finally
+ {
+ stop( server );
+ }
+ }
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ private String defaultNsUri = "tcp://127.0.0.1:8002";
+
+ public String getDefaultNsUri()
+ {
+ return defaultNsUri;
+ }
+
+ public void setDefaultNsUri( String defaultNsUri )
+ {
+ this.defaultNsUri = defaultNsUri;
+ }
+
+ @Override
+ public void shutdown()
+ {
+ recordsBySession.clear();
+ serversByNsUri.clear();
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/DefaultNSLib.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,408 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns.support;
+
+import etch.services.ns.NameService.Entry;
+import etch.services.ns.support.DefaultNSLib;
+
+import org.apache.etch.bindings.java.msg.Message;
+import org.apache.etch.bindings.java.msg.ValueFactory;
+import org.apache.etch.bindings.java.support.ServerFactory;
+import org.apache.etch.bindings.java.support.TransportFactory;
+import org.apache.etch.bindings.java.transport.SessionMessage;
+import org.apache.etch.bindings.java.transport.TransportMessage;
+import org.apache.etch.util.AlarmListener;
+import org.apache.etch.util.AlarmManager;
+import org.apache.etch.util.Resources;
+import org.apache.etch.util.URL;
+import org.apache.etch.util.core.Who;
+import org.apache.etch.util.core.io.Session;
+import org.apache.etch.util.core.io.Transport;
+
+
+/**
+ * Transport factory abstraction for the Naming Service enhancement
+ */
+
+public class EtchTransportFactory extends TransportFactory
+{
+ public final static String LISTENER_URI = "suri";
+ public final static String LISTENER_REGISTERED_URI = "curi";
+ public final static String NS_URI = "nsuri";
+ public final static String RECONNECT_TERM = "reconnectDelay";
+
+ static
+ {
+ TransportFactory.define( "etch", new EtchTransportFactory() );
+ NSLib.setInstance( new DefaultNSLib() );
+ }
+
+ @Override
+ protected Transport<ServerFactory> newListener( String uri,
+ Resources resources ) throws Exception
+ {
+ String listenerUri;
+ URL u = new URL( uri );
+
+ // Extract uri for the listener to listen on
+ if ( !u.hasTerm( LISTENER_URI ) )
+ throw new IllegalArgumentException( "listener uri not configured properly within the etch uri" );
+
+ listenerUri = u.getTerm( LISTENER_URI );
+
+ // call to create transport stack underneath
+ Transport<ServerFactory> transport = TransportFactory.getListener( listenerUri, resources );
+ EtchSessionListener esl = new EtchSessionListener( transport, uri, resources );
+
+ return esl;
+ }
+
+ @Override
+ protected TransportMessage newTransport( String uri, Resources resources )
+ throws Exception
+ {
+ // create an etch blob and return
+ return new EtchTransport( uri, resources );
+ }
+
+ // Etch blob that intercepts client messages
+ private class EtchTransport implements TransportMessage, SessionMessage, AlarmListener
+ {
+ public TransportMessage transport;
+ public SessionMessage session;
+ public Resources resources;
+ public String uri;
+ public int reconnect = 0;
+
+ /**
+ *
+ * @param etchUri uri based on the etch scheme
+ * @param resources
+ */
+ public EtchTransport( String uri, Resources resources )
+ {
+ this.resources = resources;
+ this.uri = uri;
+
+ URL u = new URL( uri );
+ if ( u.hasTerm( RECONNECT_TERM ) )
+ reconnect = u.getIntegerTerm( RECONNECT_TERM, 0 );
+
+ }
+
+ @Override
+ public void transportMessage( Who recipient, Message msg )
+ throws Exception
+ {
+ transport.transportMessage( recipient, msg );
+ }
+
+ @Override
+ public SessionMessage getSession()
+ {
+ return session;
+ }
+
+ @Override
+ public void setSession( SessionMessage session )
+ {
+ this.session = session;
+ }
+
+ @Override
+ public void transportControl( Object control, Object value )
+ throws Exception
+ {
+ // Create a new transport stack
+ if ( control == START_AND_WAIT_UP || control == START )
+ {
+ Entry targetEntry = DefaultNSLib.staticLookup( uri );
+
+ if ( targetEntry == null )
+ throw new Exception( "No such registered listener: " + uri );
+
+ String targetUri = targetEntry.getTargetUri();
+
+ TransportMessage m = TransportFactory.getTransport( targetUri, resources );
+
+ m.setSession( this );
+
+ try
+ {
+ m.transportControl( control, value );
+
+ // only if above works
+ transport = m;
+
+ }
+ catch( Exception e )
+ {
+ // in case the transport doesn't start up
+ // or throws a timeout exception
+ m.transportControl( STOP, null );
+ m.setSession( null );
+ throw e;
+ }
+ return;
+ }
+
+ // destroy the transport stack when connection goes down
+ if ( control == STOP || control == STOP_AND_WAIT_DOWN )
+ {
+ TransportMessage m = transport;
+ if ( m != null )
+ {
+ transport = null;
+ m.transportControl( control, value );
+ }
+ return;
+ }
+
+ if ( transport != null )
+ transport.transportControl( control, value );
+ else
+ throw new UnsupportedOperationException( "no transport " +
+ "to implement the control: " + control );
+ }
+
+ @Override
+ public void transportNotify( Object event ) throws Exception
+ {
+ if ( transport != null )
+ transport.transportNotify( event );
+ }
+
+ @Override
+ public Object transportQuery( Object query ) throws Exception
+ {
+ if ( transport != null )
+ return transport.transportQuery( query );
+
+ throw new UnsupportedOperationException( "no transport " +
+ "to implement the query: " + query );
+
+ }
+
+ @Override
+ public boolean sessionMessage( Who sender, Message msg )
+ throws Exception
+ {
+ return session.sessionMessage( sender, msg );
+ }
+
+ @Override
+ public void sessionControl( Object control, Object value )
+ throws Exception
+ {
+ session.sessionControl( control, value );
+ }
+
+ @Override
+ public void sessionNotify( Object event ) throws Exception
+ {
+ /*
+ * Handle the listener going down
+ */
+ session.sessionNotify( event );
+
+ if ( event == DOWN )
+ {
+ if ( this.transport == null )
+ {
+ // this notify is as a result of the client shutdown
+ AlarmManager.shutdown();
+ return;
+ }
+
+ if ( reconnect > 0 )
+ AlarmManager.staticAdd( this, null, reconnect );
+
+ // The transport has been stopped
+ // Now, discard this transport stack
+ transport = null;
+ }
+ }
+
+ @Override
+ public Object sessionQuery( Object query ) throws Exception
+ {
+ return session.sessionQuery( query );
+ }
+
+ @Override
+ public int wakeup( AlarmManager manager, Object state, long due )
+ {
+ try
+ {
+ // throws exception if connection is DOWN
+ transportControl( START_AND_WAIT_UP, 4000 );
+
+ // remove alarm if transportControl successful
+ return 0;
+ }
+ catch( Exception e )
+ {
+ try
+ {
+ this.sessionNotify( e );
+ }
+ catch( Exception e1 )
+ {
+ e1.printStackTrace();
+ }
+ return reconnect;
+ }
+ }
+ }
+
+ private class EtchSessionListener implements Transport<ServerFactory>
+ {
+
+ private Transport<ServerFactory> transport;
+ private String uri;
+ String nsUri;
+
+ public EtchSessionListener( Transport<ServerFactory> transport, String uri, Resources resources )
+ {
+ this.transport = transport;
+ transport.setSession( session );
+ this.uri = uri;
+ }
+ private ServerFactory session = new ServerFactory()
+ {
+ private ServerFactory _session;
+ @Override
+ public void newServer( String arg0, Resources arg1,
+ TransportMessage arg2 ) throws Exception
+ {
+ _session.newServer( arg0, arg1, arg2 );
+ }
+
+ @Override
+ public ValueFactory newValueFactory()
+ {
+ return _session.newValueFactory();
+ }
+
+ @Override
+ public void sessionControl( Object arg0, Object arg1 )
+ throws Exception
+ {
+ _session.sessionControl( arg0, arg1 );
+ }
+
+ @Override
+ public void sessionNotify( Object arg0 ) throws Exception
+ {
+ _session.sessionNotify( arg0 );
+ }
+
+ @Override
+ public Object sessionQuery( Object arg0 ) throws Exception
+ {
+ return _session.sessionQuery( arg0 );
+ }
+
+ @Override
+ public Session getSession()
+ {
+ return _session;
+ }
+
+ @Override
+ public void setSession( Session arg0 )
+ {
+ _session = (ServerFactory)arg0;
+ }
+
+ @Override
+ public void transportControl( Object arg0, Object arg1 )
+ throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void transportNotify( Object arg0 ) throws Exception
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object transportQuery( Object arg0 ) throws Exception
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ @Override
+ public void transportControl( Object control, Object value )
+ throws Exception
+ {
+
+ transport.transportControl( control, value );
+
+ if ( control == START || control == START_AND_WAIT_UP )
+ {
+ // register to the naming service here
+ DefaultNSLib.staticRegister( getSession(), uri, null, 0 );
+
+ return;
+ }
+
+ if ( control == STOP || control == STOP_AND_WAIT_DOWN )
+ {
+ // unregister from the name service
+ DefaultNSLib.staticUnregister( getSession(), uri, false );
+
+ return;
+ }
+ }
+
+ @Override
+ public void transportNotify( Object event ) throws Exception
+ {
+ transport.transportNotify( event );
+ }
+
+ @Override
+ public Object transportQuery( Object query ) throws Exception
+ {
+ return transport.transportQuery( query );
+ }
+
+ @Override
+ public ServerFactory getSession()
+ {
+ return (ServerFactory) session.getSession();
+ }
+
+ @Override
+ public void setSession( ServerFactory session )
+ {
+ this.session.setSession( session );
+ }
+ }
+
+
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/EtchTransportFactory.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,168 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns.support;
+
+import java.util.Map;
+
+import org.apache.etch.util.core.io.Session;
+
+import etch.services.ns.NameService.Entry;
+
+/**
+ *
+ * Class that acts as an interface between core etch and the naming service.
+ *
+ * NOTE: One NSLib instance deals with only one connection to the name service
+ *
+ */
+public abstract class NSLib
+{
+ public final static int RECONNECT_DELAY = 4000;
+ private final static Object instanceSync = new Object();
+
+ public NSLib(){}
+ public static NSLib instance;
+
+ /**
+ * Get an instance of NSLib
+ *
+ * @return a new instance of NSLib
+ */
+ public static NSLib getInstance()
+ {
+
+ /*if ( instance == null )
+ {
+ synchronized ( instanceSync )
+ {
+ if ( instance == null )
+ instance = instance.getImplInstance();
+ }
+ }*/
+ return instance;
+ }
+
+ /**
+ * Get the default NSUri for this NSLib
+ * @return the default NSUri
+ */
+ public static String staticGetDefaultNsUri()
+ {
+ return getInstance().getDefaultNsUri();
+ }
+
+ /**
+ * Sets the default NSUri for this NSLib
+ * @param defaultNsUri the new default NsUri
+ */
+ public static void staticSetDefaultNsUri( String defaultNsUri )
+ {
+ getInstance().setDefaultNsUri( defaultNsUri );
+ }
+
+ /**
+ *
+ * @param newInstance
+ * @return old instance
+ */
+ public static NSLib setInstance( NSLib newInstance )
+ {
+ synchronized ( instanceSync )
+ {
+ NSLib oldInstance = instance;
+ instance = newInstance;
+ return oldInstance;
+ }
+ }
+
+ public static void staticShutdown()
+ {
+ NSLib oldInstance = setInstance( null );
+ if ( oldInstance != null )
+ oldInstance.shutdown();
+ }
+
+ /**
+ * Obtain instance of the specific NSLib implementation
+ * @return
+ */
+ public abstract NSLib getImplInstance();
+
+ /**
+ * Cleanup method for the NSLib implementation
+ */
+ public abstract void shutdown();
+
+ /**
+ * Get the default naming service uri in case none specific in the uris
+ * @return default naming service uri
+ */
+ public abstract String getDefaultNsUri();
+
+ /**
+ * Set the default naming service uri
+ * @param defaultNsUri default naming service uri
+ */
+ public abstract void setDefaultNsUri( String defaultNsUri );
+
+ /**
+ * Adapter for the Name Service register, please refer to ns.etch for additional
+ * documentation
+ *
+ * @param session session listener session object to report errors
+ * to the name service
+ * @param nsUri name service uri. If null, defaultNsUri is used.
+ */
+ public static void staticRegister( Session session, String uri, Map<?,?> qualities, int ttl )
+ {
+ NSLib.getInstance().register( session, uri, qualities, ttl );
+ }
+
+ /**
+ * Unregister a listener from the name service
+ *
+ * @param session listener session object to report errors
+ * @param uri uri provided by listener
+ */
+ public static void staticUnregister( Session session, String uri, boolean deleteEntry )
+ {
+ NSLib.getInstance().unregister( session, uri, deleteEntry );
+ }
+
+ /**
+ * Look up the target uri of the supplied source from the name service
+ *
+ * @param nsUri name service uri. If null, defaultNsUri is used.
+ * @param sourceUri sourceUri of the target service
+ * @return an entry containing all the details of the target service
+ */
+ public static Entry staticLookup( String uri )
+ {
+ return NSLib.getInstance().lookup( uri );
+ }
+
+ public abstract void register( Session session, String uri, Map<?,?> qualities, int ttl );
+
+ public abstract void unregister( Session session, String uri, boolean deleteEntry );
+
+ public abstract Entry lookup( String uri );
+
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/main/java/etch/services/ns/support/NSLib.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java (added)
+++ incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,359 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package etch.services.ns.support;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.etch.bindings.java.support.ServerFactory;
+import org.apache.etch.util.core.io.Session;
+import org.apache.etch.util.core.io.Transport;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import etch.services.ns.MainNameServiceListener;
+import etch.services.ns.NameServiceHelper;
+import etch.services.ns.NameService.Entry;
+
+public class TestNSLib
+{
+ private static String defaultNSUri = null;
+ private static String listenerUri = "etch:sourceListener?suri=listenerUri&curi=targetListener&nsuri=tcp://127.0.0.1:8002";
+ private static String clientUri = "etch://127.0.0.1:8002/sourceListener";
+ private static String testSourceUri1 = "sourceListener";
+ private static String testtargetUri1 = "targetListener";
+ private static ServerFactory nsListener;
+
+ @BeforeClass
+ public static void startNS()
+ {
+ NSLib.setInstance( new DefaultNSLib() );
+ defaultNSUri = NSLib.staticGetDefaultNsUri();
+ try
+ {
+ nsListener = NameServiceHelper.newListener( defaultNSUri, null,
+ new MainNameServiceListener() );
+ nsListener.transportControl( Transport.START_AND_WAIT_UP, 4000 );
+ }
+ catch( Exception e )
+ {
+ System.out.println( e );
+ }
+ }
+
+ @Test ( expected = IllegalArgumentException.class )
+ public void register1()
+ {
+ // null case
+
+ NSLib.staticRegister( null, null, null, 0 );
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void register2() throws Exception
+ {
+ String uri = "suri=listenerUri&curi=targetListener&nsuri=tcp://127.0.0.1:8002";
+ NSLib.staticRegister( new MySession(), uri, null, 0 );
+ }
+
+ @Test
+ public void register4() throws Exception
+ {
+ MySession session = new MySession();
+
+ NSLib.staticRegister( session, listenerUri, null, 0 );
+
+ // small delay to let registration complete
+ Thread.sleep( 250 );
+
+ Entry e = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ NSLib.staticUnregister( session, listenerUri, false );
+
+ Entry e1 = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e1.sourceUri );
+ assertEquals( null, e1.targetUri ); // since removed
+ assertEquals( 0, e1.ttl );
+ assertEquals( null, e1.qualities );
+ }
+
+ @Test
+ public void register5() throws Exception
+ {
+ // Don't pass the nsUri
+ // everything should work because of defaultNSUri
+
+ MySession session = new MySession();
+
+ String uri = "etch:sourceListener?suri=listenerUri&curi=targetListener";
+
+ NSLib.staticRegister( session, uri, null, 0 );
+
+ // small delay to let registration complete
+ Thread.sleep( 250 );
+
+ String curi = "etch:sourceListener";
+ Entry e = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ NSLib.staticUnregister( session, uri, false );
+
+ Entry e1 = NSLib.staticLookup( curi );
+
+ assertEquals( testSourceUri1, e1.sourceUri );
+ assertEquals( null, e1.targetUri ); // since removed
+ assertEquals( 0, e1.ttl );
+ assertEquals( null, e1.qualities );
+ }
+
+ @Test
+ public void register6() throws Exception
+ {
+ // 1. Don't pass the nsUri
+ // 2. Pass "true" in unregister
+ // Verify that entry was deleted
+
+ MySession session = new MySession();
+
+ String uri = "etch:sourceListener?suri=listenerUri&curi=targetListener";
+
+ NSLib.staticRegister( session, uri, null, 0 );
+
+ // small delay to let registration complete
+ Thread.sleep( 250 );
+
+ String curi = "etch:sourceListener";
+ Entry e = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ NSLib.staticUnregister( session, uri, true );
+
+ Entry e1 = NSLib.staticLookup( curi );
+
+ assertNull( e1 );
+ }
+
+ @Test
+ public void register7() throws Exception
+ {
+ // register 3 listeners
+
+ MySession session = new MySession();
+ NSLib.staticRegister( session, listenerUri, null, 0 );
+
+ MySession session2 = new MySession();
+ String listenerUri1 = "etch:sourceListener2?suri=listenerUri&curi=targetListener2&nsuri=tcp://127.0.0.1:8002";
+ NSLib.staticRegister( session2, listenerUri1, null, 0 );
+
+ MySession session3 = new MySession();
+ String listenerUri2 = "etch:sourceListener3?suri=listenerUri&curi=targetListener3&nsuri=tcp://127.0.0.1:8002";
+ NSLib.staticRegister( session3, listenerUri2, null, 0 );
+
+ Thread.sleep( 250 );
+
+ Entry e = NSLib.staticLookup( clientUri );
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ String clientUri1 = "etch://127.0.0.1:8002/sourceListener2";
+ e = NSLib.staticLookup( clientUri1 );
+ assertEquals( testSourceUri1 + "2", e.sourceUri );
+ assertEquals( testtargetUri1 + "2", e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ String clientUri2 = "etch://127.0.0.1:8002/sourceListener3";
+ e = NSLib.staticLookup( clientUri2 );
+ assertEquals( testSourceUri1 + "3", e.sourceUri );
+ assertEquals( testtargetUri1 + "3", e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ NSLib.staticUnregister( session, listenerUri, true );
+ NSLib.staticUnregister( session2, listenerUri1, true );
+ NSLib.staticUnregister( session3, listenerUri2, true );
+
+ /**
+ * Just to make sure that the above entries are removed from the name service
+ * (because we reconnect after every RECONNECT_DELAY millis)
+ */
+ Thread.sleep( NSLib.RECONNECT_DELAY + 1000 );
+
+ e = NSLib.staticLookup( clientUri );
+ assertNull( e );
+
+ e = NSLib.staticLookup( clientUri1 );
+ assertNull( e );
+
+ e = NSLib.staticLookup( clientUri2 );
+ assertNull( e );
+ }
+
+ @Test ( expected = IllegalArgumentException.class )
+ public void lookup1() throws Exception
+ {
+ NSLib.staticLookup( null );
+ }
+
+ @Test
+ public void lookup2() throws Exception
+ {
+ // verify that you don't need a register to do a lookup
+ NSLib.staticLookup( clientUri );
+ }
+
+ @Test
+ public void lookup3() throws Exception
+ {
+ MySession session = new MySession();
+ NSLib.staticRegister( session, listenerUri, null, 0 );
+
+ Thread.sleep( 250 );
+
+ String clientUri1 = "etch://127.0.0.1:8002/invalidSourceUri";
+ Entry e = NSLib.staticLookup( clientUri1 );
+
+ assertEquals( null, e );
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void unregister1() throws Exception
+ {
+ NSLib.staticUnregister( null, null, false );
+ }
+
+ @Test( expected = IllegalArgumentException.class )
+ public void unregister2() throws Exception
+ {
+ Session session = new MySession();
+ String listenerUri1 = "suri=listenerUri&curi=targetListener&nsuri=tcp://127.0.0.1:8002";
+
+ NSLib.staticUnregister( session, listenerUri1, false );
+ }
+
+ @Test
+ public void unregister3() throws Exception
+ {
+ Session session = new MySession();
+ NSLib.staticRegister( session, listenerUri, null, 0 );
+
+ Thread.sleep( 250 );
+
+ // try unregistering an invalid entry
+ String listenerUri1 = "etch:sourceListener_invalid?suri=listenerUri&curi=targetListener&nsuri=tcp://127.0.0.1:8002";
+ NSLib.staticUnregister( session, listenerUri1, true );
+
+ // above unregister doesn't affect existing entry in NS table
+
+ Entry e = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+ }
+
+ @Test
+ public void nsDown1() throws Exception
+ {
+ /**
+ * test that the NSLib alarm functionality works fine
+ * - test that register(...) is being called every RECONNECT_DELAY units
+ */
+ Session session = new MySession();
+ NSLib.staticRegister( session, listenerUri, null, 0 );
+
+ // stop the naming service
+ nsListener.transportControl( Transport.STOP_AND_WAIT_DOWN, 4000 );
+
+ Thread.sleep( 1000 ); //breather
+
+ // start the naming service
+ nsListener.transportControl( Transport.START_AND_WAIT_UP, 4000 );
+
+ Thread.sleep( NSLib.RECONNECT_DELAY ); // worst case reconnect would take this much time
+
+ Entry e = NSLib.staticLookup( clientUri );
+
+ assertEquals( testSourceUri1, e.sourceUri );
+ assertEquals( testtargetUri1, e.targetUri );
+ assertEquals( 0, e.ttl );
+ assertEquals( null, e.qualities );
+
+ }
+
+ @AfterClass
+ public static void endNS()
+ {
+ try
+ {
+ nsListener.transportControl( Transport.STOP_AND_WAIT_DOWN, 4000 );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Mock session
+ *
+ */
+ private class MySession implements Session
+ {
+ @Override
+ public void sessionControl( Object arg0, Object arg1 ) throws Exception
+ {
+ System.out.println( "session control" );
+ }
+
+ @Override
+ public void sessionNotify( Object arg0 ) throws Exception
+ {
+ System.out.println( "session notify: " + arg0 );
+ }
+
+ @Override
+ public Object sessionQuery( Object arg0 ) throws Exception
+ {
+ System.out.println( "sessionQuery: " + arg0 );
+ return null;
+ }
+
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/src/test/java/etch/services/ns/support/TestNSLib.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java (added)
+++ incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,45 @@
+// This file automatically generated by:
+// Apache Etch 1.1.0-incubating (LOCAL-0) / java 1.1.0-incubating (LOCAL-0)
+// Sat Feb 21 22:11:51 CST 2009
+// This file is automatically created and should not be edited!
+// Re-implement these methods by overriding them in ImplNameServiceClient.
+
+package etch.services.ns;
+
+import org.apache.etch.bindings.java.support.ObjSession;
+
+
+/**
+ * Base implementation of NameServiceClient, with default method implementations
+ * which throw UnsupportedOperationException. Extend this class to provide
+ * implementations of messages from the server.
+ *
+ * @see ImplNameServiceClient
+ */
+public class BaseNameServiceClient implements NameServiceClient, ObjSession
+{
+ public Object _sessionQuery( Object query ) throws Exception
+ {
+ throw new UnsupportedOperationException( "unknown query: "+query );
+ }
+
+ public void _sessionControl( Object control, Object value ) throws Exception
+ {
+ throw new UnsupportedOperationException( "unknown control: "+control );
+ }
+
+ public void _sessionNotify( Object event ) throws Exception
+ {
+ if (event instanceof Throwable)
+ ((Throwable) event).printStackTrace();
+ }
+
+ public void entryChanged
+ (
+ String query
+ , etch.services.ns.NameService.Entry entry
+ )
+ {
+ throw new UnsupportedOperationException( "entryChanged" );
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceClient.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java (added)
+++ incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,148 @@
+// This file automatically generated by:
+// Apache Etch 1.1.0-incubating (LOCAL-0) / java 1.1.0-incubating (LOCAL-0)
+// Sat Feb 21 22:11:51 CST 2009
+// This file is automatically created and should not be edited!
+// Re-implement these methods by overriding them in ImplNameServiceServer.
+
+package etch.services.ns;
+
+import org.apache.etch.bindings.java.support.ObjSession;
+
+
+/**
+ * Base implementation of NameServiceServer, with default method implementations
+ * which throw UnsupportedOperationException. Extend this class to provide
+ * implementations of messages from the client.
+ *
+ * @see ImplNameServiceServer
+ */
+public class BaseNameServiceServer implements NameServiceServer, ObjSession
+{
+ public Object _sessionQuery( Object query ) throws Exception
+ {
+ throw new UnsupportedOperationException( "unknown query: "+query );
+ }
+
+ public void _sessionControl( Object control, Object value ) throws Exception
+ {
+ throw new UnsupportedOperationException( "unknown control: "+control );
+ }
+
+ public void _sessionNotify( Object event ) throws Exception
+ {
+ if (event instanceof Throwable)
+ ((Throwable) event).printStackTrace();
+ }
+
+ public etch.services.ns.NameService.Entry lookup
+ (
+ String source
+ )
+ {
+ throw new UnsupportedOperationException( "lookup" );
+ }
+
+ public etch.services.ns.NameService.Entry[] find
+ (
+ String query
+ , Integer offset
+ , Integer count
+ )
+ {
+ throw new UnsupportedOperationException( "find" );
+ }
+
+ public void register
+ (
+ String sourceUri
+ , java.util.Map<?, ?> qualities
+ , String targetUri
+ , Integer ttl
+ )
+ {
+ throw new UnsupportedOperationException( "register" );
+ }
+
+ public void registerBulk
+ (
+ etch.services.ns.NameService.Entry[] entries
+ )
+ {
+ throw new UnsupportedOperationException( "registerBulk" );
+ }
+
+ public void unregister
+ (
+ String sourceUri
+ , Boolean deleteEntry
+ )
+ {
+ throw new UnsupportedOperationException( "unregister" );
+ }
+
+ public void subscribe
+ (
+ String query
+ )
+ {
+ throw new UnsupportedOperationException( "subscribe" );
+ }
+
+ public void unsubscribe
+ (
+ String query
+ )
+ {
+ throw new UnsupportedOperationException( "unsubscribe" );
+ }
+
+ public void unsubscribeAll
+ (
+ )
+ {
+ throw new UnsupportedOperationException( "unsubscribeAll" );
+ }
+
+ public Boolean canLookup
+ (
+ String source
+ )
+ {
+ throw new UnsupportedOperationException( "canLookup" );
+ }
+
+ public Boolean canFind
+ (
+ String query
+ )
+ {
+ throw new UnsupportedOperationException( "canFind" );
+ }
+
+ public Boolean canRegister
+ (
+ String sourceUri
+ , java.util.Map<?, ?> qualities
+ , String targetUri
+ )
+ {
+ throw new UnsupportedOperationException( "canRegister" );
+ }
+
+ public Boolean canUnregister
+ (
+ String sourceUri
+ , Boolean deleteEntry
+ )
+ {
+ throw new UnsupportedOperationException( "canUnregister" );
+ }
+
+ public Boolean canRegisterBulk
+ (
+ etch.services.ns.NameService.Entry[] entries
+ )
+ {
+ throw new UnsupportedOperationException( "canRegisterBulk" );
+ }
+}
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/BaseNameServiceServer.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java (added)
+++ incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,315 @@
+// This file automatically generated by:
+// Apache Etch 1.1.0-incubating (LOCAL-0) / java 1.1.0-incubating (LOCAL-0)
+// Sat Feb 21 22:11:51 CST 2009
+// This file is automatically created and should not be edited!
+
+package etch.services.ns;
+
+import java.io.Serializable;
+
+
+/**
+ * The NameService provides translation from an abstract name for a service to a
+ * uri that may be used to contact the service. A given service may offer
+ * several different connection schemes, and a client may only support a subset
+ * of those. So, when a client wishes to connect to a service, it may query
+ * the NameService with both abstract name and desired schemes in order to find
+ * a suitable match.
+ *
+ * Some example queries:
+ *
+ * All services with servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * sourceUri='Foo/bar/tcp'
+ *
+ * Same as the query above, but written out longhand:
+ *
+ * servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * Fully qualified sourceUri:
+ *
+ * sourceUri='Foo/bar/tcp/1'
+ *
+ * Any instance of service Foo located in Austin, TX:
+ *
+ * servicename='Foo' and qualities.location='Austin, TX'
+ *
+ * Instances of service Foo with capacity >= 400:
+ *
+ * servicename='Foo' and qualities.capacity>=400
+ *
+ * Relative operations on qualities require that the quality be present and be
+ * comparable (with mixed types some type promotion is supported). But you might
+ * be surprised, qualities which are absent will give a negative comparison no
+ * matter which sense is used: both qualities.x > 50 and qualities.x < 50 are
+ * false whenever qualities.x is null. Consider this test: not qualities.x < 50.
+ * This is not the same as qualities.x >= 50. It is the same as qualities.x =
+ * null or qualities.x >= 50.
+ */
+@SuppressWarnings("unused")
+public interface NameService
+{
+ /**
+ * An entry describing a service.
+ */
+ @SuppressWarnings("serial")
+ public class Entry
+ implements Serializable
+ {
+ /**
+ * Constructs the Entry. Don't init any fields.
+ */
+ public Entry()
+ {
+ // don't init any fields.
+ }
+
+ /**
+ * Constructs the Entry.
+ * @param sourceUri A service description uri, composed of
+ * sourceUri servicename/instancename/qualifier[/priority].
+ * @param qualities Qualities of this service instance.
+ * @param targetUri Etch service connection uri, for example
+ * targetUri tcp://localhost:9000?filter=KeepAlive
+ * @param ttl Lifetime in seconds from last update.
+ * @param who Who created or last update.
+ * @param lastUpdate Date / time of create or last update.
+ * @param removed Flag indicating entry has been removed.
+ */
+ public Entry
+ (
+ String sourceUri
+ , java.util.Map<?, ?> qualities
+ , String targetUri
+ , Integer ttl
+ , String who
+ , java.util.Date lastUpdate
+ , Boolean removed
+ )
+ {
+ this.sourceUri = sourceUri;
+ this.qualities = qualities;
+ this.targetUri = targetUri;
+ this.ttl = ttl;
+ this.who = who;
+ this.lastUpdate = lastUpdate;
+ this.removed = removed;
+ }
+
+ @Override
+ public String toString()
+ {
+ return String.format( "Entry(sourceUri=%s; qualities=%s; targetUri=%s; ttl=%s; who=%s; lastUpdate=%s; removed=%s)", sourceUri, qualities, targetUri, ttl, who, lastUpdate, removed );
+ }
+
+ /**
+ * A service description uri, composed of
+ * servicename/instancename/qualifier[/priority].
+ */
+ public String sourceUri;
+
+ /**
+ * Gets the value.
+ *
+ * A service description uri, composed of
+ * servicename/instancename/qualifier[/priority].
+ *
+ * @return the value.
+ */
+ public String getSourceUri()
+ {
+ return sourceUri;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * A service description uri, composed of
+ * servicename/instancename/qualifier[/priority].
+ *
+ * @param value the value.
+ */
+ public void setSourceUri( String value )
+ {
+ this.sourceUri = value;
+ }
+
+ /**
+ * Qualities of this service instance.
+ */
+ public java.util.Map<?, ?> qualities;
+
+ /**
+ * Gets the value.
+ *
+ * Qualities of this service instance.
+ *
+ * @return the value.
+ */
+ public java.util.Map<?, ?> getQualities()
+ {
+ return qualities;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Qualities of this service instance.
+ *
+ * @param value the value.
+ */
+ public void setQualities( java.util.Map<?, ?> value )
+ {
+ this.qualities = value;
+ }
+
+ /**
+ * Etch service connection uri, for example
+ * tcp://localhost:9000?filter=KeepAlive
+ */
+ public String targetUri;
+
+ /**
+ * Gets the value.
+ *
+ * Etch service connection uri, for example
+ * tcp://localhost:9000?filter=KeepAlive
+ *
+ * @return the value.
+ */
+ public String getTargetUri()
+ {
+ return targetUri;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Etch service connection uri, for example
+ * tcp://localhost:9000?filter=KeepAlive
+ *
+ * @param value the value.
+ */
+ public void setTargetUri( String value )
+ {
+ this.targetUri = value;
+ }
+
+ /**
+ * Lifetime in seconds from last update.
+ */
+ public Integer ttl;
+
+ /**
+ * Gets the value.
+ *
+ * Lifetime in seconds from last update.
+ *
+ * @return the value.
+ */
+ public Integer getTtl()
+ {
+ return ttl;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Lifetime in seconds from last update.
+ *
+ * @param value the value.
+ */
+ public void setTtl( Integer value )
+ {
+ this.ttl = value;
+ }
+
+ /**
+ * Who created or last update.
+ */
+ public String who;
+
+ /**
+ * Gets the value.
+ *
+ * Who created or last update.
+ *
+ * @return the value.
+ */
+ public String getWho()
+ {
+ return who;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Who created or last update.
+ *
+ * @param value the value.
+ */
+ public void setWho( String value )
+ {
+ this.who = value;
+ }
+
+ /**
+ * Date / time of create or last update.
+ */
+ public java.util.Date lastUpdate;
+
+ /**
+ * Gets the value.
+ *
+ * Date / time of create or last update.
+ *
+ * @return the value.
+ */
+ public java.util.Date getLastUpdate()
+ {
+ return lastUpdate;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Date / time of create or last update.
+ *
+ * @param value the value.
+ */
+ public void setLastUpdate( java.util.Date value )
+ {
+ this.lastUpdate = value;
+ }
+
+ /**
+ * Flag indicating entry has been removed.
+ */
+ public Boolean removed;
+
+ /**
+ * Gets the value.
+ *
+ * Flag indicating entry has been removed.
+ *
+ * @return the value.
+ */
+ public Boolean getRemoved()
+ {
+ return removed;
+ }
+
+ /**
+ * Sets the value.
+ *
+ * Flag indicating entry has been removed.
+ *
+ * @param value the value.
+ */
+ public void setRemoved( Boolean value )
+ {
+ this.removed = value;
+ }
+ }
+
+}
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameService.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java?rev=746631&view=auto
==============================================================================
--- incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java (added)
+++ incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java Sun Feb 22 04:17:56 2009
@@ -0,0 +1,71 @@
+// This file automatically generated by:
+// Apache Etch 1.1.0-incubating (LOCAL-0) / java 1.1.0-incubating (LOCAL-0)
+// Sat Feb 21 22:11:51 CST 2009
+// This file is automatically created and should not be edited!
+
+package etch.services.ns;
+
+
+
+/**
+ * The NameService provides translation from an abstract name for a service to a
+ * uri that may be used to contact the service. A given service may offer
+ * several different connection schemes, and a client may only support a subset
+ * of those. So, when a client wishes to connect to a service, it may query
+ * the NameService with both abstract name and desired schemes in order to find
+ * a suitable match.
+ *
+ * Some example queries:
+ *
+ * All services with servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * sourceUri='Foo/bar/tcp'
+ *
+ * Same as the query above, but written out longhand:
+ *
+ * servicename='Foo' and instancename='bar' and qualifier='tcp'
+ *
+ * Fully qualified sourceUri:
+ *
+ * sourceUri='Foo/bar/tcp/1'
+ *
+ * Any instance of service Foo located in Austin, TX:
+ *
+ * servicename='Foo' and qualities.location='Austin, TX'
+ *
+ * Instances of service Foo with capacity >= 400:
+ *
+ * servicename='Foo' and qualities.capacity>=400
+ *
+ * Relative operations on qualities require that the quality be present and be
+ * comparable (with mixed types some type promotion is supported). But you might
+ * be surprised, qualities which are absent will give a negative comparison no
+ * matter which sense is used: both qualities.x > 50 and qualities.x < 50 are
+ * false whenever qualities.x is null. Consider this test: not qualities.x < 50.
+ * This is not the same as qualities.x >= 50. It is the same as qualities.x =
+ * null or qualities.x >= 50.
+ */
+@SuppressWarnings("unused")
+public interface NameServiceClient extends NameService
+{
+ /**
+ * Notifies the client of a change in an entry. The entry might have been
+ * created, updated, or removed.
+ *
+ * Note: while this might have normally been an event, we made it a call
+ * to slow down the processing of what might otherwise be a rather large
+ * change set.
+ *
+ * Note: when keeping track of entries, always keep the one with the latest
+ * lastUpdate.
+ *
+ * @param query the query which triggered the notification.
+ *
+ * @param entry the entry which has changed.
+ */
+ public void entryChanged(
+ String query
+ , etch.services.ns.NameService.Entry entry
+ )
+ ;
+}
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/branches/name-service/services/ns/target/generated-sources/main/etch/java/etch/services/ns/NameServiceClient.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"