incubator-river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r939061 - in /incubator/river/jtsk/trunk/src: com/sun/jini/discovery/ net/jini/core/discovery/ net/jini/core/lookup/ net/jini/discovery/ net/jini/io/ net/jini/lookup/
Date Wed, 28 Apr 2010 19:28:58 GMT
Author: peter_firmstone
Date: Wed Apr 28 19:28:57 2010
New Revision: 939061

URL: http://svn.apache.org/viewvc?rev=939061&view=rev
Log:
A significant number of changes to  the new StreamServiceRegistrar.

This is very experimental please comment, suggest improvements etc, where new classes should
go etc.

Note changes to follow for methods signatures as per Chris Dolan's suggestions.

Also please check for backward compatibility issues.

Added:
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java   (with
props)
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java   (with props)
    incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceRegistrarFacade.java
      - copied, changed from r937157, incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java
    incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java   (with
props)
    incubator/river/jtsk/trunk/src/net/jini/lookup/StreamServiceRegistrarFacade.java
      - copied, changed from r937160, incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java
Removed:
    incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java
    incubator/river/jtsk/trunk/src/net/jini/io/FromMOInputStream.java
    incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceInputStream.java
    incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstanceOutputStream.java
    incubator/river/jtsk/trunk/src/net/jini/io/ToMOInputStream.java
Modified:
    incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java
    incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
    incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
    incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java
    incubator/river/jtsk/trunk/src/net/jini/io/Convert.java
    incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java
    incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java
    incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java
    incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java
    incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java

Modified: incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java (original)
+++ incubator/river/jtsk/trunk/src/com/sun/jini/discovery/UnicastResponse.java Wed Apr 28
19:28:57 2010
@@ -21,7 +21,7 @@ package com.sun.jini.discovery;
 import java.util.Arrays;
 import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
-import net.jini.discovery.ServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 
 /**
  * Class representing the values obtained as the result of unicast discovery.

Modified: incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/discovery/LookupLocator.java Wed Apr 28 19:28:57
2010
@@ -35,8 +35,8 @@ import javax.net.SocketFactory;
 import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
 import net.jini.core.lookup.StreamServiceRegistrar;
-import net.jini.discovery.ServiceRegistrarFacade;
-import net.jini.discovery.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
+import net.jini.lookup.StreamServiceRegistrarFacade;
 import net.jini.io.MarshalledInstance;
 import net.jini.io.MoToMiInputStream;
 

Added: incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java?rev=939061&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java Wed Apr
28 19:28:57 2010
@@ -0,0 +1,52 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.core.lookup;
+
+import java.io.IOException;
+import net.jini.core.entry.Entry;
+
+/**
+ * MarshalledServiceItem extends ServiceItem and can be used anywhere a 
+ * ServiceItem can.  A MarshalledServiceItem implementation instance 
+ * contains the marshalled form of a Service and it's Entry's,
+ * the corresponding superclass ServiceItem however contains null values
+ * for the service and can exclude any Entry's. 
+ * 
+ * The ServiceID shall be in unmarshalled form always in the ServiceItem super class.
+ * 
+ * Since the ServiceItem.service is null, use of this class in existing software
+ * will not return the service, however it will not break that software as
+ * ServiceItem's contract is to set service or Entry's to null when they cannot
+ * be unmarshalled.
+ * 
+ * ServiceItem's toString() method will return a different result for
+ * MarshalledServiceItem instances.
+ * 
+ * If required, a new ServiceItem that is fully unmarshalled 
+ * can be constructed from this class's methods and ServiceID.
+ * 
+ * @author Peter Firmstone.
+ */
+public abstract class MarshalledServiceItem extends ServiceItem{
+    private static final long SerialVersionUID = 1L;
+    protected MarshalledServiceItem(ServiceID id, Entry[] unmarshalledEntries){
+        super(id, (Object) null, unmarshalledEntries);
+    }
+    /**
+     * Unmarshall the service proxy.
+     * @return the service proxy.
+     * @throws java.io.IOException
+     * @throws java.lang.ClassNotFoundException 
+     */
+    public abstract Object getService() throws IOException, ClassNotFoundException;
+    /**
+     * Unmarshall the Entry's
+     * @return array of Entry's
+     * @throws java.io.IOException
+     * @throws java.lang.ClassNotFoundException
+     */
+    public abstract Entry[] getEntries() throws IOException, ClassNotFoundException;
+}

Propchange: incubator/river/jtsk/trunk/src/net/jini/core/lookup/MarshalledServiceItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java?rev=939061&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java Wed Apr 28 19:28:57
2010
@@ -0,0 +1,19 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.core.lookup;
+
+/**
+ * This interface is similar to an Enumerator, it is designed to return
+ * results incrementally in loops, however unlike an Enumerator, there is no
+ * check first operation as implementors must return a null value after
+ * the backing data source has been exhausted. So this terminates like a stream
+ * by returning a null value.
+ * 
+ * @author Peter Firmstone
+ */
+public interface ResultStream<T> {
+    public T get();
+}

Propchange: incubator/river/jtsk/trunk/src/net/jini/core/lookup/ResultStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/core/lookup/StreamServiceRegistrar.java Wed Apr
28 19:28:57 2010
@@ -17,8 +17,8 @@
  */
 package net.jini.core.lookup;
 
-import java.io.ObjectInput;
 import java.rmi.RemoteException;
+import net.jini.core.entry.Entry;
 import net.jini.core.event.EventRegistration;
 import net.jini.core.event.RemoteEventListener;
 import net.jini.io.MarshalledInstance;
@@ -84,28 +84,109 @@ public interface StreamServiceRegistrar 
 	throws RemoteException;
 
     /**
-     * Returns the service object (i.e., just ServiceItem.service) from an
-     * item matching the template.  It makes the service object available via
-     * the returned ObjectInput.  
+     * Returns a ResultStream that provides access to MarshalledServiceItem 
+     * instances.  The ResultStream terminates with a null value.  The result
+     * stream may be infinite.
      * 
-     * If the returned object cannot be deserialized, it can be returned in
-     * marshalled form as a MarshalledInstance.
+     * MarshalledServiceItem extends ServiceItem and can be used anywhere a 
+     * ServiceItem can.  A MarshalledServiceItem implementation instance 
+     * contains the marshalled form of a Service and it's Entry's,
+     * the corresponding superclass ServiceItem however contains null values
+     * for the service and excludes any Entry's that are not specifically requested
+     * unmarshalled by this method. The ServiceID will be unmarshalled always.
      * 
-     * Implementations of this interface should return the Objects in order of
-     * their package implementation version, so that the number of ClassLoaders
-     * are minimised and common packages can share code.  This is intended to
-     * be used with the new codebase services (TODO once implemented).
+     * This method is designed to allow the caller to control exactly what
+     * is unmarshalled and when, it allows unmarshalling of specific entries
+     * that the caller may wish to utilise for filtering. It is
+     * designed to allow both the caller and the implementer to deal with very
+     * large result sets in an incremental fashion.
      * 
-     * ObjectInput should be an InputStream, in order to minimise
-     * memory consumption requirements at the client.
+     * It is absolutely essential that the caller deletes any references to
+     * the returned result stream as soon as it is no longer requried.
      *
      * @param tmpl template to match
-     * @param marshalled if true return objects in marshalled form.
-     * @return an object input that represents a service that matches the
      * specified template
+     * @param unmarshalledEntries only Entry's with these classes will be in
+     * unmarshalled form.
+     * @param maxBatchSize Allows the caller to limit the number of results
+     * held locally, larger batch sizes reduce network traffic, but may delay
+     * processing locally depending on implementation.
+     * @return ResultStream containing ServiceItem's
      * @throws java.rmi.RemoteException
-     * @see MarshalledInstance
+     * @see MarshalledServiceItem
+     * @see ServiceItem
+     * @see ResultStream
+     * @see ServiceResultStreamFilter
      * @since 2.2.0
      */
-    ObjectInput lookup(ServiceTemplate tmpl, boolean marshalled) throws RemoteException;
+    ResultStream<MarshalledServiceItem> lookup(ServiceTemplate tmpl, 
+        Class<? extends Entry>[] unmarshalledEntries, int maxBatchSize) throws RemoteException;
+    
+    /**
+     * Looks at all service items that match the specified template, finds
+     * every entry (among those service items) that either doesn't match any
+     * entry templates or is a subclass of at least one matching entry
+     * template, and returns the set of the (most specific) classes of those
+     * entries.  Duplicate classes are eliminated, and the order of classes
+     * within the returned array is arbitrary.  Null (not an empty array) is
+     * returned if there are no such entries or no matching items.  If a
+     * returned class cannot be deserialized, that element of the returned
+     * array is set to null and no exception is thrown.
+     *
+     * @param tmpl template to match
+     * @param maxBatchSize 
+     * @return a ResultStream of entry Classes (attribute sets) for every service
+     * that matches the specified template
+     * @throws java.rmi.RemoteException
+     */
+    ResultStream<Class> getEntryClasses(ServiceTemplate tmpl, int maxBatchSize) 
+            throws RemoteException;
+
+    /**
+     * Looks at all service items that match the specified template, finds
+     * every entry (among those service items) that matches
+     * tmpl.attributeSetTemplates[setIndex], and returns the set of values
+     * of the specified field of those entries.  Duplicate values are
+     * eliminated, and the order of values isarbitrary.  
+     * If a returned value cannot be deserialized, that
+     * element is excluded and no exception is thrown.
+     *
+     * @param tmpl template to match
+     * @param setIndex index into tmpl.attributeSetTemplates
+     * @param field name of field of tmpl.attributeSetTemplates[setIndex]
+     *
+     * @param maxBatchSize 
+     * @return a ResultStream of objects that represents field values of entries
+     * associated with services that meet the specified matching
+     * criteria
+     *
+     * @throws NoSuchFieldException field does not name a field of the
+     * entry template
+     * @throws java.rmi.RemoteException
+     */
+    ResultStream getFieldValues(ServiceTemplate tmpl, int setIndex, String field,
+            int maxBatchSize) throws NoSuchFieldException, RemoteException;
+    
+    /**
+     * Looks at all service items that match the specified template, and for
+     * every service item finds the most specific type (class or interface)
+     * or types the service item is an instance of that are neither equal to,
+     * nor a superclass of, any of the service types in the template and that
+     * have names that start with the specified prefix, and returns the set
+     * of all such types.  Duplicate types are eliminated, and the order of
+     * types within the returned array is arbitrary.  
+     * Null is returned if there are no such types.  If a returned type
+     * cannot be deserialized, that element is excluded and no exception is thrown.
+     *
+     * @param tmpl template to match
+     * @param prefix class name prefix
+     *
+     * @param maxBatchSize 
+     * @return an array of Classes of all services that either match the
+     * specified template or match the specified prefix
+     * @throws java.rmi.RemoteException
+     */
+    ResultStream<Class> getServiceTypes(ServiceTemplate tmpl, String prefix, 
+            int maxBatchSize) throws RemoteException;
+
 }

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/ConstrainableLookupLocator.java Wed
Apr 28 19:28:57 2010
@@ -18,6 +18,8 @@
 
 package net.jini.discovery;
 
+import net.jini.lookup.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 import com.sun.jini.discovery.Discovery;
 import com.sun.jini.discovery.DiscoveryConstraints;
 import com.sun.jini.discovery.UnicastResponse;

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscMan2Facade.java Wed Apr 28 19:28:57
2010
@@ -5,6 +5,7 @@
 
 package net.jini.discovery;
 
+import net.jini.lookup.ServiceRegistrarFacade;
 import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
 

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscManFacade.java Wed Apr 28 19:28:57
2010
@@ -5,6 +5,7 @@
 
 package net.jini.discovery;
 
+import net.jini.lookup.ServiceRegistrarFacade;
 import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceRegistrar;
 

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/DiscoveryEvent.java Wed Apr 28 19:28:57
2010
@@ -17,6 +17,8 @@
  */
 package net.jini.discovery;
 
+import net.jini.lookup.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EventObject;

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/IncomingUnicastResponse.java Wed Apr
28 19:28:57 2010
@@ -17,6 +17,7 @@
  */
 package net.jini.discovery;
 
+import net.jini.lookup.ServiceRegistrarFacade;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -92,7 +93,7 @@ public class IncomingUnicastResponse {
     /**
      * Return the lookup portable service registrar we have discovered.
      * 
-     * For maximum platform compatbility don't downcast to ServiceRegistrar,
+     * For maximum platform compatbility don't downcast,
      * use PortableServiceRegistrar where possible.
      *
      * @return the lookup service registrar we have discovered

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscovery.java Wed Apr 28 19:28:57
2010
@@ -17,6 +17,8 @@
  */
 package net.jini.discovery;
 
+import net.jini.lookup.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 import com.sun.jini.config.Config;
 import com.sun.jini.discovery.Discovery;
 import com.sun.jini.discovery.DiscoveryConstraints;

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupDiscoveryManager.java Wed Apr
28 19:28:57 2010
@@ -18,6 +18,7 @@
 
 package net.jini.discovery;
 
+import net.jini.lookup.ServiceRegistrarFacade;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupLocatorDiscovery.java Wed Apr
28 19:28:57 2010
@@ -17,6 +17,8 @@
  */
 package net.jini.discovery;
 
+import net.jini.lookup.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 import com.sun.jini.config.Config;
 import com.sun.jini.discovery.Discovery;
 import com.sun.jini.discovery.DiscoveryConstraints;

Modified: incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/discovery/LookupUnmarshalException.java Wed Apr
28 19:28:57 2010
@@ -18,6 +18,8 @@
 
 package net.jini.discovery;
 
+import net.jini.lookup.StreamServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 import net.jini.core.lookup.ServiceRegistrar;
 import net.jini.core.lookup.PortableServiceRegistrar;
 

Modified: incubator/river/jtsk/trunk/src/net/jini/io/Convert.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/Convert.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/Convert.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/Convert.java Wed Apr 28 19:28:57 2010
@@ -20,9 +20,10 @@ package net.jini.io;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
-import java.util.Collections;
+import java.io.ObjectStreamClass;
 
 /**
  * Rather than utilise a static class, an empty object class can be utilised
@@ -41,13 +42,17 @@ public class Convert<T> {
         convert = converter;
     }
     
+    /**
+     * Get the non generic, plain object, unchecked Convert instance.
+     * @return
+     */
     public static Convert getInstance(){
         return convert;
     }
-    protected Convert(){}
+    Convert(){}
     
-    @SuppressWarnings("unchecked")
-    public java.rmi.MarshalledObject<T> 
+    @SuppressWarnings("unchecked") 
+    java.rmi.MarshalledObject<T> 
             toRmiMarshalledObject(net.jini.io.MarshalledObject<T> privateMO){
         // To create a java.rmi.MarshalledObject with previously
 	// serialized data we first create a private
@@ -74,17 +79,18 @@ public class Convert<T> {
 	return mo;
     }
     
-    private net.jini.io.MarshalledInstance<T> toMarshalledInstance(
+    net.jini.io.MarshalledInstance<T> toMarshalledInstance(
             net.jini.io.MarshalledObject<T> mo){
         return new MarshalledInstance<T>(mo);
     }
     
-    private net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
+    net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
             net.jini.io.MarshalledInstance<T> instance){
         return instance.asMarshalledObject();
     }
     
-    private net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
+    @SuppressWarnings("unchecked")
+    net.jini.io.MarshalledObject<T> toJiniMarshalledObject(
             java.rmi.MarshalledObject<T> instance){
         net.jini.io.MarshalledObject<T> privateMO = null;
 	try {
@@ -110,11 +116,41 @@ public class Convert<T> {
 	return toRmiMarshalledObject(instance.asMarshalledObject());
     }
     
+    @SuppressWarnings("unchecked")
     public MarshalledInstance<T> 
             toMarshalledInstance(java.rmi.MarshalledObject<T> instance){
         if ( instance == null ) throw new NullPointerException("null reference");
         net.jini.io.MarshalledObject obj = toJiniMarshalledObject(instance);
         if ( obj == null ) throw new NullPointerException("null reference");
 	return new MarshalledInstance<T>(obj);
-    }  
+    }
+    
+    private static class FromMOInputStream extends ObjectInputStream {
+
+        public FromMOInputStream(InputStream in) throws IOException {
+            super(in);
+        }
+
+        @Override
+        protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
+            if (desc.getName().equals("java.rmi.MarshalledObject")) {
+                return net.jini.io.MarshalledObject.class;
+            }
+            return super.resolveClass(desc);
+        }
+    }
+    
+    private static class ToMOInputStream extends ObjectInputStream {
+        public ToMOInputStream(InputStream in) throws IOException {
+            super(in);
+        }
+
+        @Override
+        protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
+            if (desc.getName().equals("net.jini.io.MarshalledObject")) {
+                return java.rmi.MarshalledObject.class;
+            }
+            return super.resolveClass(desc);
+        }
+    }
 }

Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledInstance.java Wed Apr 28 19:28:57
2010
@@ -20,10 +20,12 @@ package net.jini.io;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ObjectStreamException;
+import java.io.OutputStream;
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Collection;
@@ -195,22 +197,9 @@ public class MarshalledInstance<T> imple
 	// version of MarshalledObject allows access to the needed
 	// fields.
 	//
-	net.jini.io.MarshalledObject privateMO = null;
-	try {
-	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-	    ObjectOutputStream oos = new ObjectOutputStream(baos);
-	    oos.writeObject(mo);
-	    oos.flush();
-	    byte[] bytes = baos.toByteArray();
-	    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-	    ObjectInputStream ois = new FromMOInputStream(bais);
-	    privateMO =
-		(net.jini.io.MarshalledObject)ois.readObject();
-	} catch (IOException ioe) {
-	    throw new AssertionError(ioe);
-	} catch (ClassNotFoundException cnfe) {
-	    throw new AssertionError(cnfe);
-	}
+        Convert<T> convert = new Convert<T>();
+	net.jini.io.MarshalledObject<T> privateMO = 
+                convert.toJiniMarshalledObject(mo);
 	objBytes = privateMO.objBytes;
 	locBytes = privateMO.locBytes;
 	hash = privateMO.hash;
@@ -231,37 +220,8 @@ public class MarshalledInstance<T> imple
     @SuppressWarnings("unchecked")
     @Deprecated
     public java.rmi.MarshalledObject<T> convertToMarshalledObject() {
-
-	// To create a java.rmi.MarshalledObject with previously
-	// serialized data we first create a private
-	// net.jini.io.MarshalledObject with the
-	// data and then convert it to the final object by changing
-	// the class during readObject(). (See resolveClass() in
-	// ToMOInputStream)
-	//
-	net.jini.io.MarshalledObject<T> privateMO =
-		new net.jini.io.MarshalledObject<T>();
-
-	privateMO.objBytes = objBytes;
-	privateMO.locBytes = locBytes;
-	privateMO.hash = hash;
-
-	java.rmi.MarshalledObject<T> mo = null;
-	try {
-	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-	    ObjectOutputStream oos = new ObjectOutputStream(baos);
-	    oos.writeObject(privateMO);
-	    oos.flush();
-	    byte[] bytes = baos.toByteArray();
-	    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-	    ObjectInputStream ois = new ToMOInputStream(bais);
-	    mo = (java.rmi.MarshalledObject<T>)ois.readObject();
-	} catch (IOException ioe) {
-	    throw new AssertionError(ioe);
-	} catch (ClassNotFoundException cnfe) {
-	    throw new AssertionError(cnfe);
-	}
-	return mo;
+        Convert convert = Convert.getInstance();
+        return convert.toRmiMarshalledObject(this);
     }
     
     MarshalledObject<T> asMarshalledObject(){
@@ -459,5 +419,55 @@ public class MarshalledInstance<T> imple
      */
     private void readObjectNoData() throws ObjectStreamException {
 	throw new InvalidObjectException("Bad class hierarchy");
-    }    
+    } 
+    
+    private static class MarshalledInstanceInputStream extends MarshalInputStream {
+
+        private ObjectInputStream locIn;
+
+        MarshalledInstanceInputStream(InputStream objIn, InputStream locIn, ClassLoader defaultLoader,
boolean verifyCodebaseIntegrity, ClassLoader verifierLoader, Collection context) throws IOException
{
+            super(objIn, defaultLoader, verifyCodebaseIntegrity, verifierLoader, context);
+            this.locIn = (locIn == null ? null : new ObjectInputStream(locIn));
+        }
+
+        @Override
+        protected String readAnnotation() throws IOException, ClassNotFoundException {
+            return locIn == null ? null : (String) locIn.readObject();
+        }
+    }
+    
+    private static class MarshalledInstanceOutputStream extends MarshalOutputStream {
+
+        private ObjectOutputStream locOut;
+        /** <code>true</code> if non-<code>null</code> annotations
are
+         *  written.
+         */
+        private boolean hadAnnotations;
+
+        public MarshalledInstanceOutputStream(OutputStream objOut, OutputStream locOut, Collection
context) throws IOException {
+            super(objOut, context);
+            this.locOut = new ObjectOutputStream(locOut);
+            hadAnnotations = false;
+        }
+
+        /**
+         * Returns <code>true</code> if any non-<code>null</code>
location
+         * annotations have been written to this stream.
+         */
+        public boolean hadAnnotations() {
+            return hadAnnotations;
+        }
+
+        @Override
+        protected void writeAnnotation(String loc) throws IOException {
+            hadAnnotations |= (loc != null);
+            locOut.writeObject(loc);
+        }
+
+        @Override
+        public void flush() throws IOException {
+            super.flush();
+            locOut.flush();
+        }
+    }
 }

Modified: incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MarshalledObject.java Wed Apr 28 19:28:57 2010
@@ -21,10 +21,10 @@ package net.jini.io;
 import java.io.Serializable;
 
 /**
- * This is a private class used to convert <code>java.rmi.MarshalledObject</code>
+ * This is a package private class used to convert <code>java.rmi.MarshalledObject</code>
  * to <code>MarshalledInstance</code> and vice versa.
  */
-public final class MarshalledObject<T> implements Serializable {
+final class MarshalledObject<T> implements Serializable {
 
     // Duplicate (private) MarshalledObject fields, and make them
     // package visable

Modified: incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MiToMoOutputStream.java Wed Apr 28 19:28:57
2010
@@ -32,11 +32,12 @@ import java.util.logging.Logger;
  * an RMI MarshalledObject Serialized form.
  * 
  * This is a nasty horrible hack to write the output stream as a 
- * java.rmi.MarshalledObject, so the CDC PersonalProfile version 1.12
- * can share this object.
+ * java.rmi.MarshalledObject, so existing classes can support
+ * Java CDC PersonalProfile version 1.12, without altering their serialized
+ * form.
  * 
  * Since this class accesses the private state of ObjectStreamClass, it is
- * tied to it's internal implementation, however since this class also
+ * tied to it's internal implementation, however since ObjectStreamClass also
  * implements Serializable, its internal state has been publicly published
  * so must remain compatible.
  * 

Modified: incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/io/MoToMiInputStream.java Wed Apr 28 19:28:57
2010
@@ -93,11 +93,4 @@ public class MoToMiInputStream extends O
         return desc;
     }
 
-//    @Override
-//    protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
-//        if (desc.getName().equals("java.rmi.MarshalledObject")) {
-//            return net.jini.io.MarshalledInstance.class;
-//        }
-//        return super.resolveClass(desc);
-//    }
 }

Modified: incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java?rev=939061&r1=939060&r2=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/JoinManager.java Wed Apr 28 19:28:57 2010
@@ -59,7 +59,7 @@ import net.jini.discovery.DiscoveryListe
 import net.jini.discovery.DiscoveryManagement2;
 import net.jini.discovery.DiscMan2Facade;
 import net.jini.discovery.Facade;
-import net.jini.discovery.ServiceRegistrarFacade;
+import net.jini.lookup.ServiceRegistrarFacade;
 
 /**
  * A goal of any well-behaved service is to advertise the facilities and

Copied: incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceRegistrarFacade.java (from r937157,
incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java)
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceRegistrarFacade.java?p2=incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceRegistrarFacade.java&p1=incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java&r1=937157&r2=939061&rev=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/ServiceRegistrarFacade.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceRegistrarFacade.java Wed Apr 28
19:28:57 2010
@@ -3,7 +3,7 @@
  * and open the template in the editor.
  */
 
-package net.jini.discovery;
+package net.jini.lookup;
 
 import java.rmi.MarshalledObject;
 import java.rmi.RemoteException;
@@ -18,6 +18,7 @@ import net.jini.core.lookup.ServiceRegis
 import net.jini.core.lookup.ServiceRegistration;
 import net.jini.core.lookup.ServiceTemplate;
 import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.discovery.Facade;
 import net.jini.io.Convert;
 import net.jini.io.MarshalledInstance;
 

Added: incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java?rev=939061&view=auto
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java (added)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java Wed Apr
28 19:28:57 2010
@@ -0,0 +1,50 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package net.jini.lookup;
+
+import net.jini.core.lookup.ResultStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import net.jini.core.lookup.MarshalledServiceItem;
+
+/**
+ * A Filter utility class designed to filter out unwanted results.  Filters can
+ * be daisy chained with pre prepared filters to perform logical AND operations.
+ * 
+ * Logical OR operations can be simulated by providing multiple filters in
+ * constructors.
+ * 
+ * Any references to ServiceResultStreamFilter should be set to null 
+ * immediately after filtering.
+ * New instances can be created as required.
+ * 
+ * @author Peter Firmstone.
+ */
+public class ServiceResultStreamFilter implements ResultStream<MarshalledServiceItem>
{
+    private final List<ServiceItemFilter> filters;
+    private final ResultStream<MarshalledServiceItem> inputResultStream;
+    
+    public ServiceResultStreamFilter(ResultStream<MarshalledServiceItem> rs,
+            ServiceItemFilter[] sf){
+        inputResultStream = rs;
+        filters = new ArrayList<ServiceItemFilter>(sf.length);
+        filters.addAll(Arrays.asList(sf));
+    }
+
+    public MarshalledServiceItem get() {
+        for(MarshalledServiceItem item = inputResultStream.get(); item != null; 
+                item = inputResultStream.get()) {
+            int l = filters.size();
+            for ( int i = 0; i < l; i++){
+                ServiceItemFilter filter = filters.get(i);
+                if(filter == null)  continue;
+                if( filter.check(item) )  return item;
+            }// end filter loop
+        }//end item loop
+        return null; // Our stream terminated item was null;
+    }
+}

Propchange: incubator/river/jtsk/trunk/src/net/jini/lookup/ServiceResultStreamFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: incubator/river/jtsk/trunk/src/net/jini/lookup/StreamServiceRegistrarFacade.java (from
r937160, incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java)
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/trunk/src/net/jini/lookup/StreamServiceRegistrarFacade.java?p2=incubator/river/jtsk/trunk/src/net/jini/lookup/StreamServiceRegistrarFacade.java&p1=incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java&r1=937160&r2=939061&rev=939061&view=diff
==============================================================================
--- incubator/river/jtsk/trunk/src/net/jini/discovery/StreamServiceRegistrarFacade.java (original)
+++ incubator/river/jtsk/trunk/src/net/jini/lookup/StreamServiceRegistrarFacade.java Wed Apr
28 19:28:57 2010
@@ -3,13 +3,15 @@
  * and open the template in the editor.
  */
 
-package net.jini.discovery;
+package net.jini.lookup;
 
-import java.io.ObjectInput;
+import net.jini.core.lookup.ResultStream;
 import java.rmi.RemoteException;
 import net.jini.core.discovery.LookupLocator;
+import net.jini.core.entry.Entry;
 import net.jini.core.event.EventRegistration;
 import net.jini.core.event.RemoteEventListener;
+import net.jini.core.lookup.MarshalledServiceItem;
 import net.jini.core.lookup.PortableServiceRegistrar;
 import net.jini.core.lookup.ServiceID;
 import net.jini.core.lookup.ServiceItem;
@@ -17,6 +19,7 @@ import net.jini.core.lookup.ServiceMatch
 import net.jini.core.lookup.ServiceRegistration;
 import net.jini.core.lookup.ServiceTemplate;
 import net.jini.core.lookup.StreamServiceRegistrar;
+import net.jini.discovery.Facade;
 import net.jini.io.Convert;
 import net.jini.io.MarshalledInstance;
 
@@ -58,16 +61,6 @@ public class StreamServiceRegistrarFacad
         }
     }
 
-    public ObjectInput lookup(ServiceTemplate tmpl, boolean marshalled)
-            throws RemoteException {
-        if ( psr instanceof StreamServiceRegistrar ){
-            StreamServiceRegistrar ssr = (StreamServiceRegistrar) psr;
-            return ssr.lookup(tmpl, marshalled);
-        }
-        throw new UnsupportedOperationException("Not supported yet.");
-        //We could make an empty implementation that doesn't return any matches?
-    }
-
     public Class[] getEntryClasses(ServiceTemplate tmpl) throws RemoteException {
         return psr.getEntryClasses(tmpl);
     }
@@ -131,4 +124,30 @@ public class StreamServiceRegistrarFacad
         return psr;
     }
 
+    public ResultStream<MarshalledServiceItem> lookup(ServiceTemplate tmpl, 
+            Class<? extends Entry>[] unmarshalledEntries, int maxBatchSize) 
+            throws RemoteException {
+        if ( psr instanceof StreamServiceRegistrar ){
+            StreamServiceRegistrar ssr = (StreamServiceRegistrar) psr;
+            return ssr.lookup(tmpl, unmarshalledEntries, maxBatchSize);
+        }
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public ResultStream<Class> getEntryClasses(ServiceTemplate tmpl, 
+            int maxBatchSize) throws RemoteException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public ResultStream getFieldValues(ServiceTemplate tmpl, int setIndex, 
+            String field, int maxBatchSize)
+            throws NoSuchFieldException, RemoteException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    public ResultStream<Class> getServiceTypes(ServiceTemplate tmpl, 
+            String prefix, int maxBatchSize) throws RemoteException {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
 }



Mime
View raw message