river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject svn commit: r724980 [4/6] - in /incubator/river/jtsk/skunk/niclas1/services/reggie: ./ src/ src/main/ src/main/java/ src/main/java/com/ src/main/java/com/sun/ src/main/java/com/sun/jini/ src/main/java/com/sun/jini/reggie/ src/main/resources/ src/main/r...
Date Wed, 10 Dec 2008 05:14:32 GMT
Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLease.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLease.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLease.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLease.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,205 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import com.sun.jini.lease.AbstractLease;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import net.jini.core.lease.Lease;
+import net.jini.core.lease.LeaseMap;
+import net.jini.core.lookup.ServiceID;
+import net.jini.id.ReferentUuid;
+import net.jini.id.ReferentUuids;
+import net.jini.id.Uuid;
+
+/**
+ * The base class for lease proxies.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+abstract class RegistrarLease extends AbstractLease implements ReferentUuid
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * The registrar.
+     *
+     * @serial
+     */
+    final Registrar server;
+    /**
+     * The registrar's service ID.
+     */
+    transient ServiceID registrarID;
+    /**
+     * The internal lease id.
+     *
+     * @serial
+     */
+    final Uuid leaseID;
+
+    /**
+     * Simple constructor.
+     */
+    RegistrarLease( Registrar server,
+                    ServiceID registrarID,
+                    Uuid leaseID,
+                    long expiration )
+    {
+        super( expiration );
+        this.server = server;
+        this.registrarID = registrarID;
+        this.leaseID = leaseID;
+    }
+
+    /**
+     * Creates a lease map.
+     */
+    public LeaseMap createLeaseMap( long duration )
+    {
+        return new RegistrarLeaseMap( this, duration );
+    }
+
+    /**
+     * Two leases can be batched if they are both RegistrarLeases and
+     * have the same server.
+     */
+    public boolean canBatch( Lease lease )
+    {
+        return ( lease instanceof RegistrarLease &&
+                 registrarID.equals( ( (RegistrarLease) lease ).registrarID ) );
+    }
+
+    /**
+     * Returns the lease Uuid.
+     */
+    public Uuid getReferentUuid()
+    {
+        return leaseID;
+    }
+
+    /**
+     * Returns the lease Uuid's hash code.
+     */
+    public int hashCode()
+    {
+        return leaseID.hashCode();
+    }
+
+    /**
+     * Returns true if lease Uuids match, false otherwise.
+     */
+    public boolean equals( Object obj )
+    {
+        return ReferentUuids.compare( this, obj );
+    }
+
+    /**
+     * Returns a string created from the proxy class name, the registrar's
+     * service ID, the id of the lessee or event (depending on the subclass),
+     * and the result of the underlying server proxy's toString method.
+     *
+     * @return String
+     */
+    public String toString()
+    {
+        String className = getClass().getName();
+        return className + "[registrar=" + registrarID + " " + server
+               + ", lease=" + leaseID + ", " + getLeaseType() + "=" + getRegID()
+               + "]";
+    }
+
+
+    /**
+     * Returns the registrar.
+     */
+    Registrar getRegistrar()
+    {
+        return server;
+    }
+
+    /**
+     * Returns the registrar's service ID.
+     */
+    ServiceID getRegistrarID()
+    {
+        return registrarID;
+    }
+
+    /**
+     * Returns the service ID, or the event ID as a Long.
+     */
+    abstract Object getRegID();
+
+    /**
+     * Returns the type of the lease.
+     */
+    abstract String getLeaseType();
+
+    /**
+     * Sets the expiration.
+     */
+    void setExpiration( long expiration )
+    {
+        this.expiration = expiration;
+    }
+
+    /**
+     * Writes the default serializable field values for this instance, followed
+     * by the registrar's service ID encoded as specified by the
+     * ServiceID.writeBytes method.
+     */
+    private void writeObject( ObjectOutputStream out ) throws IOException
+    {
+        out.defaultWriteObject();
+        registrarID.writeBytes( out );
+    }
+
+    /**
+     * Reads the default serializable field values for this instance, followed
+     * by the registrar's service ID encoded as specified by the
+     * ServiceID.writeBytes method.  Verifies that the deserialized field
+     * values are non-null.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+        registrarID = new ServiceID( in );
+        if( server == null )
+        {
+            throw new InvalidObjectException( "null server" );
+        }
+        else if( leaseID == null )
+        {
+            throw new InvalidObjectException( "null leaseID" );
+        }
+    }
+
+    /**
+     * Throws InvalidObjectException, since data for this class is required.
+     */
+    private void readObjectNoData() throws ObjectStreamException
+    {
+        throw new InvalidObjectException( "no data" );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLeaseMap.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLeaseMap.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLeaseMap.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarLeaseMap.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,162 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import com.sun.jini.lease.AbstractLeaseMap;
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import net.jini.core.lease.LeaseMapException;
+import net.jini.core.lookup.ServiceID;
+import net.jini.id.Uuid;
+
+/**
+ * The LeaseMap implementation class for registrar leases.  Clients only see
+ * instances via the LeaseMap interface.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class RegistrarLeaseMap extends AbstractLeaseMap
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * The registrar.
+     *
+     * @serial
+     */
+    final Registrar server;
+    /**
+     * The registrar's service ID.
+     *
+     * @serial
+     */
+    final ServiceID registrarID;
+
+    /**
+     * Simple constructor
+     */
+    RegistrarLeaseMap( RegistrarLease lease, long duration )
+    {
+        this( lease.getRegistrar(), lease, duration );
+    }
+
+    /**
+     * Constructor used by ConstrainableRegistrarLeaseMap
+     */
+    RegistrarLeaseMap( Registrar server, RegistrarLease lease, long duration )
+    {
+        super( lease, duration );
+        this.server = server;
+        registrarID = lease.getRegistrarID();
+    }
+
+    /**
+     * Any RegistrarLease from the same server can be in the map
+     */
+    public boolean canContainKey( Object key )
+    {
+        return ( key instanceof RegistrarLease &&
+                 registrarID.equals( ( (RegistrarLease) key ).getRegistrarID() ) );
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public void renewAll() throws LeaseMapException, RemoteException
+    {
+        int size = map.size();
+        if( size == 0 )
+        {
+            return;
+        }
+        Object[] regIDs = new Object[size];
+        Uuid[] leaseIDs = new Uuid[size];
+        long[] durations = new long[size];
+        int i = 0;
+        for( Iterator iter = map.entrySet().iterator(); iter.hasNext(); i++ )
+        {
+            Map.Entry e = (Map.Entry) iter.next();
+            RegistrarLease ls = (RegistrarLease) e.getKey();
+            regIDs[ i ] = ls.getRegID();
+            leaseIDs[ i ] = ls.getReferentUuid();
+            durations[ i ] = ( (Long) e.getValue() ).longValue();
+        }
+        RenewResults results = server.renewLeases( regIDs, leaseIDs, durations );
+        long now = System.currentTimeMillis();
+        HashMap emap = ( results.exceptions != null ) ?
+                       new HashMap( 2 * results.exceptions.length + 1 ) : null;
+        i = 0;
+        int j = 0;
+        for( Iterator iter = map.entrySet().iterator(); iter.hasNext(); i++ )
+        {
+            Map.Entry e = (Map.Entry) iter.next();
+            long duration = results.durations[ i ];
+            if( duration >= 0 )
+            {
+                ( (RegistrarLease) e.getKey() ).setExpiration( duration + now );
+            }
+            else
+            {
+                emap.put( e.getKey(), results.exceptions[ j++ ] );
+                iter.remove();
+            }
+        }
+        if( emap != null )
+        {
+            throw new LeaseMapException( "lease renewal failures", emap );
+        }
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public void cancelAll() throws LeaseMapException, RemoteException
+    {
+        int size = map.size();
+        if( size == 0 )
+        {
+            return;
+        }
+        Object[] regIDs = new Object[size];
+        Uuid[] leaseIDs = new Uuid[size];
+        int i = 0;
+        for( Iterator iter = map.keySet().iterator(); iter.hasNext(); i++ )
+        {
+            RegistrarLease ls = (RegistrarLease) iter.next();
+            regIDs[ i ] = ls.getRegID();
+            leaseIDs[ i ] = ls.getReferentUuid();
+        }
+        Exception[] exceptions = server.cancelLeases( regIDs, leaseIDs );
+        if( exceptions == null )
+        {
+            return;
+        }
+        i = 0;
+        HashMap emap = new HashMap( 13 );
+        for( Iterator iter = map.keySet().iterator(); iter.hasNext(); i++ )
+        {
+            RegistrarLease ls = (RegistrarLease) iter.next();
+            Exception ex = exceptions[ i ];
+            if( ex != null )
+            {
+                emap.put( ls, ex );
+                iter.remove();
+            }
+        }
+        throw new LeaseMapException( "lease cancellation failures", emap );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarPermission.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarPermission.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,61 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import net.jini.jeri.BasicInvocationDispatcher;
+import net.jini.jeri.BasicJeriExporter;
+import net.jini.security.AccessPermission;
+
+/**
+ * Permission that can be used to express the access control policy for an
+ * instance of the Reggie lookup service exported with a {@link
+ * BasicJeriExporter}.  This class can be specified to {@link
+ * BasicInvocationDispatcher}, which will then perform permission checks for
+ * incoming remote calls using <code>RegistrarPermission</code> instances.
+ * <p>
+ * An instance contains a name (also referred to as a "target name") but no
+ * actions list; you either have the named permission or you don't.  The
+ * convention is that the target name is the fully qualified name of the remote
+ * method being invoked.  Wildcard matches are supported using the syntax
+ * specified by {@link AccessPermission}.
+ * <p>
+ * The possible target names for use with a Reggie server are specified in the
+ * package documentation for {@link com.sun.jini.reggie}.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class RegistrarPermission extends AccessPermission
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * Creates an instance with the specified target name.
+     *
+     * @param name the target name
+     * @throws NullPointerException     if the target name is <code>null</code>
+     * @throws IllegalArgumentException if the target name does not match
+     *                                  the syntax specified in the comments at the beginning of the {@link
+     *                                  AccessPermission} class
+     */
+    public RegistrarPermission( String name )
+    {
+        super( name );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarProxy.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarProxy.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarProxy.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RegistrarProxy.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,317 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import com.sun.jini.proxy.MarshalledWrapper;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.rmi.MarshalledObject;
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.admin.Administrable;
+import net.jini.core.constraint.RemoteMethodControl;
+import net.jini.core.event.EventRegistration;
+import net.jini.core.event.RemoteEventListener;
+import net.jini.core.lookup.LookupLocator;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceMatches;
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.id.ReferentUuid;
+import net.jini.id.ReferentUuids;
+import net.jini.id.Uuid;
+import net.jini.id.UuidFactory;
+
+/**
+ * A RegistrarProxy is a proxy for a registrar.  Clients only see instances
+ * via the ServiceRegistrar, Administrable and ReferentUuid interfaces.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class RegistrarProxy
+    implements ServiceRegistrar, Administrable, ReferentUuid, Serializable
+{
+    private static final long serialVersionUID = 2L;
+
+    private static final Logger logger =
+        Logger.getLogger( "com.sun.jini.reggie" );
+
+    /**
+     * The registrar.
+     *
+     * @serial
+     */
+    final Registrar server;
+    /**
+     * The registrar's service ID.
+     */
+    transient ServiceID registrarID;
+
+    /**
+     * Returns RegistrarProxy or ConstrainableRegistrarProxy instance,
+     * depending on whether given server implements RemoteMethodControl.
+     */
+    static RegistrarProxy getInstance( Registrar server,
+                                       ServiceID registrarID )
+    {
+        return ( server instanceof RemoteMethodControl ) ?
+               new ConstrainableRegistrarProxy( server, registrarID, null ) :
+               new RegistrarProxy( server, registrarID );
+    }
+
+    /**
+     * Constructor for use by getInstance(), ConstrainableRegistrarProxy.
+     */
+    RegistrarProxy( Registrar server, ServiceID registrarID )
+    {
+        this.server = server;
+        this.registrarID = registrarID;
+    }
+
+    // Inherit javadoc
+    public Object getAdmin() throws RemoteException
+    {
+        return server.getAdmin();
+    }
+
+    // Inherit javadoc
+    public ServiceRegistration register( ServiceItem srvItem,
+                                         long leaseDuration )
+        throws RemoteException
+    {
+        Item item = new Item( srvItem );
+        if( item.serviceID != null )
+        {
+            Util.checkRegistrantServiceID(
+                item.serviceID, logger, Level.WARNING );
+        }
+        return server.register( item, leaseDuration );
+    }
+
+    // Inherit javadoc
+    public Object lookup( ServiceTemplate tmpl ) throws RemoteException
+    {
+        MarshalledWrapper wrapper = server.lookup( new Template( tmpl ) );
+        if( wrapper == null )
+        {
+            return null;
+        }
+        try
+        {
+            return wrapper.get();
+        }
+        catch( IOException e )
+        {
+            throw new UnmarshalException( "error unmarshalling return", e );
+        }
+        catch( ClassNotFoundException e )
+        {
+            throw new UnmarshalException( "error unmarshalling return", e );
+        }
+    }
+
+    // Inherit javadoc
+    public ServiceMatches lookup( ServiceTemplate tmpl, int maxMatches )
+        throws RemoteException
+    {
+        return server.lookup( new Template( tmpl ), maxMatches ).get();
+    }
+
+    // Inherit javadoc
+    public EventRegistration notify( ServiceTemplate tmpl,
+                                     int transitions,
+                                     RemoteEventListener listener,
+                                     MarshalledObject handback,
+                                     long leaseDuration )
+        throws RemoteException
+    {
+        return server.notify( new Template( tmpl ), transitions, listener,
+                              handback, leaseDuration );
+    }
+
+    // Inherit javadoc
+    public Class[] getEntryClasses( ServiceTemplate tmpl )
+        throws RemoteException
+    {
+        return EntryClassBase.toClass(
+            server.getEntryClasses( new Template( tmpl ) ) );
+    }
+
+    // Inherit javadoc
+    public Object[] getFieldValues( ServiceTemplate tmpl,
+                                    int setIndex, String field )
+        throws NoSuchFieldException, RemoteException
+    {
+        /* check that setIndex and field are valid, convert field to index */
+        ClassMapper.EntryField[] efields =
+            ClassMapper.getFields(
+                tmpl.attributeSetTemplates[ setIndex ].getClass() );
+        int fidx;
+        for( fidx = efields.length; --fidx >= 0; )
+        {
+            if( field.equals( efields[ fidx ].field.getName() ) )
+            {
+                break;
+            }
+        }
+        if( fidx < 0 )
+        {
+            throw new NoSuchFieldException( field );
+        }
+        Object[] values = server.getFieldValues( new Template( tmpl ),
+                                                 setIndex, fidx );
+        /* unmarshal each value, replacing with null on exception */
+        if( values != null && efields[ fidx ].marshal )
+        {
+            for( int i = values.length; --i >= 0; )
+            {
+                try
+                {
+                    values[ i ] = ( (MarshalledWrapper) values[ i ] ).get();
+                    continue;
+                }
+                catch( Throwable e )
+                {
+                    handleException( e );
+                }
+                values[ i ] = null;
+            }
+        }
+        return values;
+    }
+
+    /**
+     * Rethrow the exception if it is an Error, unless it is a LinkageError,
+     * OutOfMemoryError, or StackOverflowError.  Otherwise print the
+     * exception stack trace if debugging is enabled.
+     */
+    static void handleException( final Throwable e )
+    {
+        if( e instanceof Error &&
+            !( e instanceof LinkageError ||
+               e instanceof OutOfMemoryError ||
+               e instanceof StackOverflowError ) )
+        {
+            throw (Error) e;
+        }
+        logger.log( Level.INFO, "unmarshalling failure", e );
+    }
+
+    // Inherit javadoc
+    public Class[] getServiceTypes( ServiceTemplate tmpl, String prefix )
+        throws RemoteException
+    {
+        return ServiceTypeBase.toClass(
+            server.getServiceTypes( new Template( tmpl ),
+                                    prefix ) );
+    }
+
+    public ServiceID getServiceID()
+    {
+        return registrarID;
+    }
+
+    // Inherit javadoc
+    public LookupLocator getLocator() throws RemoteException
+    {
+        return server.getLocator();
+    }
+
+    // Inherit javadoc
+    public String[] getGroups() throws RemoteException
+    {
+        return server.getMemberGroups();
+    }
+
+    // Inherit javadoc
+    public Uuid getReferentUuid()
+    {
+        return UuidFactory.create( registrarID.getMostSignificantBits(),
+                                   registrarID.getLeastSignificantBits() );
+    }
+
+    // Inherit javadoc
+    public int hashCode()
+    {
+        return registrarID.hashCode();
+    }
+
+    /**
+     * Proxies for servers with the same service ID are considered equal.
+     */
+    public boolean equals( Object obj )
+    {
+        return ReferentUuids.compare( this, obj );
+    }
+
+    /**
+     * Returns a string created from the proxy class name, the registrar's
+     * service ID, and the result of the underlying proxy's toString method.
+     *
+     * @return String
+     */
+    public String toString()
+    {
+        return this.getClass().getName() + "[registrar=" + registrarID
+               + " " + server + "]";
+    }
+
+    /**
+     * Writes the default serializable field value for this instance, followed
+     * by the registrar's service ID encoded as specified by the
+     * ServiceID.writeBytes method.
+     */
+    private void writeObject( ObjectOutputStream out ) throws IOException
+    {
+        out.defaultWriteObject();
+        registrarID.writeBytes( out );
+    }
+
+    /**
+     * Reads the default serializable field value for this instance, followed
+     * by the registrar's service ID encoded as specified by the
+     * ServiceID.writeBytes method.  Verifies that the deserialized registrar
+     * reference is non-null.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+        registrarID = new ServiceID( in );
+        if( server == null )
+        {
+            throw new InvalidObjectException( "null server" );
+        }
+    }
+
+    /**
+     * Throws InvalidObjectException, since data for this class is required.
+     */
+    private void readObjectNoData() throws ObjectStreamException
+    {
+        throw new InvalidObjectException( "no data" );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Registration.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Registration.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Registration.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Registration.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,177 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import net.jini.core.constraint.RemoteMethodControl;
+import net.jini.core.entry.Entry;
+import net.jini.core.lease.Lease;
+import net.jini.core.lease.UnknownLeaseException;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.id.ReferentUuid;
+import net.jini.id.ReferentUuids;
+import net.jini.id.Uuid;
+
+/**
+ * Implementation class for the ServiceRegistration interface.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class Registration implements ServiceRegistration, ReferentUuid, Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * The registrar
+     *
+     * @serial
+     */
+    final Registrar server;
+    /**
+     * The service lease
+     *
+     * @serial
+     */
+    final ServiceLease lease;
+
+    /**
+     * Returns Registration or ConstrainableRegistration instance, depending on
+     * whether given server implements RemoteMethodControl.
+     */
+    static Registration getInstance( Registrar server, ServiceLease lease )
+    {
+        return ( server instanceof RemoteMethodControl ) ?
+               new ConstrainableRegistration( server, lease, null ) :
+               new Registration( server, lease );
+    }
+
+    /**
+     * Constructor for use by getInstance(), ConstrainableRegistration.
+     */
+    Registration( Registrar server, ServiceLease lease )
+    {
+        this.server = server;
+        this.lease = lease;
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public ServiceID getServiceID()
+    {
+        return lease.getServiceID();
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public Lease getLease()
+    {
+        return lease;
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public void addAttributes( Entry[] attrSets )
+        throws UnknownLeaseException, RemoteException
+    {
+        server.addAttributes( lease.getServiceID(),
+                              lease.getReferentUuid(),
+                              EntryRep.toEntryRep( attrSets, true ) );
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public void modifyAttributes( Entry[] attrSetTmpls, Entry[] attrSets )
+        throws UnknownLeaseException, RemoteException
+    {
+        server.modifyAttributes( lease.getServiceID(),
+                                 lease.getReferentUuid(),
+                                 EntryRep.toEntryRep( attrSetTmpls, false ),
+                                 EntryRep.toEntryRep( attrSets, false ) );
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public void setAttributes( Entry[] attrSets )
+        throws UnknownLeaseException, RemoteException
+    {
+        server.setAttributes( lease.getServiceID(),
+                              lease.getReferentUuid(),
+                              EntryRep.toEntryRep( attrSets, true ) );
+    }
+
+    // This method's javadoc is inherited from an interface of this class
+    public Uuid getReferentUuid()
+    {
+        return lease.getReferentUuid();
+    }
+
+    /**
+     * Returns the registration Uuid's hash code.
+     */
+    public int hashCode()
+    {
+        return lease.getReferentUuid().hashCode();
+    }
+
+    /**
+     * Returns true if registration Uuids match, false otherwise.
+     */
+    public boolean equals( Object obj )
+    {
+        return ReferentUuids.compare( this, obj );
+    }
+
+    /**
+     * Returns a string created from the proxy class name and the result
+     * of calling toString on the contained lease.
+     *
+     * @return String
+     */
+    public String toString()
+    {
+        return getClass().getName() + "[" + lease + "]";
+    }
+
+
+    /**
+     * Verifies that member fields are non-null.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+        if( server == null )
+        {
+            throw new InvalidObjectException( "null server" );
+        }
+        else if( lease == null )
+        {
+            throw new InvalidObjectException( "null lease" );
+        }
+    }
+
+    /**
+     * Throws InvalidObjectException, since data for this class is required.
+     */
+    private void readObjectNoData() throws ObjectStreamException
+    {
+        throw new InvalidObjectException( "no data" );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RenewResults.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RenewResults.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RenewResults.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/RenewResults.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,61 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.io.Serializable;
+
+/*
+ * RenewResults contains the return values of a renewLeases call on the
+ * registrar.  Instances are never visible to clients, they are private
+ * to the communication between the LeaseMap proxy and the registrar.
+ *
+ * @author Sun Microsystems, Inc.
+ *
+ */
+class RenewResults implements Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * The granted duration for each lease.  The length of this array
+     * is the same as the length of the durations parameter to renewLeases,
+     * and is in the same order.  If a duration is -1, it indicates that
+     * an exception was thrown for this lease.
+     *
+     * @serial
+     */
+    public long[] durations;
+    /**
+     * Any exceptions thrown.  The length of this array is the same as
+     * the number of -1 elements in durations.  The exceptions are in
+     * order.
+     *
+     * @serial
+     */
+    public Exception[] exceptions;
+
+    /**
+     * Simple constructor
+     */
+    public RenewResults( long[] durations, Exception[] exceptions )
+    {
+        this.durations = durations;
+        this.exceptions = exceptions;
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceLease.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceLease.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceLease.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceLease.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,142 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamException;
+import java.rmi.RemoteException;
+import net.jini.core.constraint.RemoteMethodControl;
+import net.jini.core.lease.UnknownLeaseException;
+import net.jini.core.lookup.ServiceID;
+import net.jini.id.Uuid;
+
+/**
+ * A ServiceLease is a proxy for a service registration lease at a registrar.
+ * Clients only see instances via the Lease interface.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class ServiceLease extends RegistrarLease
+{
+
+    private static final long serialVersionUID = 2L;
+    /**
+     * The type of the lease used in toString() calls.
+     */
+    private static final String LEASE_TYPE = "service";
+
+    /**
+     * The service id assigned at registration.
+     */
+    transient ServiceID serviceID;
+
+    /**
+     * Returns ServiceLease or ConstrainableServiceLease instance, depending on
+     * whether given server implements RemoteMethodControl.
+     */
+    static ServiceLease getInstance( Registrar server,
+                                     ServiceID registrarID,
+                                     ServiceID serviceID,
+                                     Uuid leaseID,
+                                     long expiration )
+    {
+        return ( server instanceof RemoteMethodControl ) ?
+               new ConstrainableServiceLease(
+                   server, registrarID, serviceID, leaseID, expiration, null ) :
+               new ServiceLease(
+                   server, registrarID, serviceID, leaseID, expiration );
+    }
+
+    /**
+     * Constructor for use by getInstance(), ConstrainableServiceLease.
+     */
+    ServiceLease( Registrar server,
+                  ServiceID registrarID,
+                  ServiceID serviceID,
+                  Uuid leaseID,
+                  long expiration )
+    {
+        super( server, registrarID, leaseID, expiration );
+        this.serviceID = serviceID;
+    }
+
+    public void cancel() throws UnknownLeaseException, RemoteException
+    {
+        server.cancelServiceLease( serviceID, leaseID );
+    }
+
+    /**
+     * Do the actual renew.
+     */
+    protected long doRenew( long duration )
+        throws UnknownLeaseException, RemoteException
+    {
+        return server.renewServiceLease( serviceID, leaseID, duration );
+    }
+
+    /**
+     * Returns the service ID
+     */
+    ServiceID getServiceID()
+    {
+        return serviceID;
+    }
+
+    Object getRegID()
+    {
+        return serviceID;
+    }
+
+    // This method's javadoc is inherited from a super class of this class
+    String getLeaseType()
+    {
+        return LEASE_TYPE;
+    }
+
+    /**
+     * Writes the service ID, encoded as specified by the ServiceID.writeBytes
+     * method.
+     */
+    private void writeObject( ObjectOutputStream out ) throws IOException
+    {
+        out.defaultWriteObject();
+        serviceID.writeBytes( out );
+    }
+
+    /**
+     * Reads the service ID, encoded as specified by the ServiceID.writeBytes
+     * method.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+        serviceID = new ServiceID( in );
+    }
+
+    /**
+     * Throws InvalidObjectException, since data for this class is required.
+     */
+    private void readObjectNoData() throws ObjectStreamException
+    {
+        throw new InvalidObjectException( "no data" );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceType.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceType.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceType.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceType.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,378 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import com.sun.jini.proxy.MarshalledWrapper;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.lang.reflect.Proxy;
+import java.rmi.MarshalException;
+import java.rmi.UnmarshalException;
+import java.security.DigestOutputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.StringTokenizer;
+import net.jini.loader.ClassLoading;
+
+/**
+ * A ServiceType is a descriptor for a class, packaged up for
+ * transmission between client-side proxies and the registrar server.
+ * Instances are never visible to clients, they are private to the
+ * communication between the proxies and the server.
+ * <p>
+ * This class only has a bare minimum of methods, to minimize
+ * the amount of code downloaded into clients.
+ *
+ * @author Sun Microsystems, Inc.
+ * @see ClassMapper
+ * @see ClassResolver
+ */
+class ServiceType implements Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+    private static final ServiceType[] empty = { };
+
+    /**
+     * Class name. If the class is generated by java.lang.reflect.Proxy,
+     * then the name is of the form ";iface1;iface2;...;ifaceN".
+     *
+     * @serial
+     */
+    private String name;
+    /**
+     * Hash for the type
+     *
+     * @serial
+     */
+    protected long hash;
+    /**
+     * Descriptor for the superclass.
+     *
+     * @serial
+     */
+    protected ServiceType superclass;
+    /**
+     * Descriptor for the interfaces.  As a special case, interfaces is
+     * null for the descriptor for java.lang.Object, and non-null otherwise.
+     * This avoids carrying a boolean isInterface around.
+     *
+     * @serial
+     */
+    protected ServiceType[] interfaces;
+    /**
+     * An instance containing only name, no supertype info.
+     * This is only used on the registrar side, to minimize the amount
+     * of info transmitted back to clients.
+     */
+    protected transient ServiceType replacement;
+    /**
+     * Flag set to true if this instance was unmarshalled from an
+     * integrity-protected stream, or false otherwise
+     */
+    private transient boolean integrity = false;
+
+    /**
+     * Should only be called by ClassMapper
+     */
+    public ServiceType( Class clazz,
+                        ServiceType superclass,
+                        ServiceType[] interfaces )
+        throws MarshalException
+    {
+        if( !Proxy.isProxyClass( clazz ) )
+        {
+            name = clazz.getName();
+        }
+        else if( interfaces.length == 0 )
+        {
+            name = ";";
+        }
+        else
+        {
+            StringBuffer buf = new StringBuffer();
+            for( int i = 0; i < interfaces.length; i++ )
+            {
+                buf.append( ';' );
+                buf.append( interfaces[ i ].getName() );
+            }
+            name = buf.toString();
+        }
+        this.superclass = superclass;
+        if( clazz != Object.class )
+        {
+            this.interfaces = interfaces;
+        }
+        try
+        {
+            computeHash();
+        }
+        catch( Exception e )
+        {
+            throw new MarshalException( "unable to calculate the type hash for "
+                                        + name, e );
+        }
+    }
+
+    /**
+     * Constructor used for creating replacement instances,
+     * containing only name.
+     */
+    private ServiceType( ServiceType stype )
+    {
+        name = stype.name;
+    }
+
+    /**
+     * Returns the name of this type
+     *
+     * @return the name of this type
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * Return the superclass descriptor
+     */
+    public ServiceType getSuperclass()
+    {
+        return superclass;
+    }
+
+    /**
+     * Return the interfaces.  The array is not a copy; do not modify it.
+     */
+    public ServiceType[] getInterfaces()
+    {
+        if( interfaces != null )
+        {
+            return interfaces;
+        }
+        return empty;
+    }
+
+    /**
+     * Return the replacement, if any, containing only name and rep.
+     */
+    public synchronized ServiceType getReplacement()
+    {
+        if( replacement == null )
+        {
+            replacement = new ServiceType( this );
+        }
+        return replacement;
+    }
+
+    /**
+     * Test if this isAssignableFrom any of the given interface types.
+     * Note ifaces cannot be null.
+     */
+    private boolean isAssignableFrom( ServiceType[] ifaces )
+    {
+        for( int i = ifaces.length; --i >= 0; )
+        {
+            if( hash == ifaces[ i ].hash ||
+                isAssignableFrom( ifaces[ i ].interfaces ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * @see Class#isInterface
+     */
+    public boolean isInterface()
+    {
+        return ( superclass == null && interfaces != null );
+    }
+
+    /**
+     * Returns true if this type is equal to <code>type</code> or if this type
+     * is equal to a superclass of <code>type</code>.
+     *
+     * @param type Type to check if subclass of this class
+     * @return true if <code>type</code> is a subclass of this type, false
+     *         otherwise
+     * @see java.lang.Class#isAssignableFrom
+     */
+    public boolean isAssignableFrom( ServiceType cls )
+    {
+        if( hash == cls.hash )
+        {
+            return true;
+        }
+        if( isInterface() )
+        {
+            if( cls.interfaces != null && isAssignableFrom( cls.interfaces ) )
+            {
+                return true;
+            }
+            for( ServiceType sup = cls.superclass;
+                 sup != null && sup.interfaces != null;
+                 sup = sup.superclass )
+            {
+                if( isAssignableFrom( sup.interfaces ) )
+                {
+                    return true;
+                }
+            }
+        }
+        else
+        {
+            for( ServiceType sup = cls.superclass;
+                 sup != null;
+                 sup = sup.superclass )
+            {
+                if( hash == sup.hash )
+                {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Converts this descriptor to a Class instance, loading from codebase
+     *
+     * @param codebase String the codebase to load the class from
+     * @return Class the class this descriptor represents
+     */
+    public Class toClass( String codebase )
+        throws IOException, ClassNotFoundException
+    {
+        if( name.charAt( 0 ) != ';' )
+        {
+            return ClassLoading.loadClass(
+                codebase, name, null, integrity, null );
+        }
+        StringTokenizer st = new StringTokenizer( name, ";" );
+        String[] ifs = new String[st.countTokens()];
+        for( int i = 0; i < ifs.length; i++ )
+        {
+            ifs[ i ] = st.nextToken();
+        }
+        return ClassLoading.loadProxyClass(
+            codebase, ifs, null, integrity, null );
+    }
+
+    /**
+     * Returns true if the object passed in is an instance of Type
+     * with the same type hash.  Returns false otherwise.
+     *
+     * @param o object to compare this object against
+     * @return true if this object equals the object passed in; false
+     *         otherwise.
+     */
+    public boolean equals( Object o )
+    {
+        if( this == o )
+        {
+            return true;
+        }
+        if( !( o instanceof ServiceType ) )
+        {
+            return false;
+        }
+        ServiceType t = (ServiceType) o;
+        return hash == t.hash;
+    }
+
+    /**
+     * Return a hashcode for this type.
+     *
+     * @return int the hashcode for this type
+     */
+    public int hashCode()
+    {
+        return (int) ( hash ^ ( hash >>> 32 ) );
+    }
+
+    /* Inherit javadoc */
+    public String toString()
+    {
+        return getClass() + "[name=" + getName() + "]";
+    }
+
+    /**
+     * Computes a SHA-1 digest from the hash of the superclass, if there
+     * is a superclass, followed by the name of this class, followed by
+     * the name and type for each field, if any, declared by this class and
+     * ordered alphabetically by field name.  The first 8 bytes of the digest
+     * are used to form the 64-bit hash value for this type.
+     */
+    private void computeHash() throws IOException, NoSuchAlgorithmException
+    {
+        hash = 0;
+        MessageDigest md = MessageDigest.getInstance( "SHA" );
+        DataOutputStream out = new DataOutputStream(
+            new DigestOutputStream( new ByteArrayOutputStream( 127 ), md ) );
+        out.writeUTF( name );
+        out.flush();
+        byte[] digest = md.digest();
+        for( int i = Math.min( 8, digest.length ); --i >= 0; )
+        {
+            hash += ( (long) ( digest[ i ] & 0xFF ) ) << ( i * 8 );
+        }
+    }
+
+    /**
+     * Samples integrity protection setting (if any) of the stream from which
+     * this instance is being deserialized.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+        if( name == null )
+        {
+            throw new InvalidObjectException( "name cannot be null" );
+        }
+        integrity = MarshalledWrapper.integrityEnforced( in );
+        if( hash == 0 )
+        {
+            try
+            {
+                computeHash();
+            }
+            catch( Exception e )
+            {
+                throw new UnmarshalException( "unable to calculate the type"
+                                              + " hash for " + name, e );
+            }
+        }
+    }
+
+    /**
+     * Throws InvalidObjectException, since data for this class is required.
+     */
+    private void readObjectNoData() throws InvalidObjectException
+    {
+        throw new InvalidObjectException( "no data" );
+    }
+
+}
+

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceTypeBase.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceTypeBase.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceTypeBase.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/ServiceTypeBase.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,88 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.io.Serializable;
+import java.rmi.server.RMIClassLoader;
+
+/**
+ * A ServiceType annotated with a codebase.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class ServiceTypeBase implements Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * The ServiceType.
+     *
+     * @serial
+     */
+    public final ServiceType type;
+    /**
+     * The codebase.
+     *
+     * @serial
+     */
+    public String codebase;
+
+    /**
+     * Simple constructor
+     */
+    public ServiceTypeBase( ServiceType type, String codebase )
+    {
+        this.type = type;
+        this.codebase = codebase;
+    }
+
+    /**
+     * Sets the codebase to the codebase of the given class.
+     */
+    public void setCodebase( Class cls )
+    {
+        codebase = RMIClassLoader.getClassAnnotation( cls );
+    }
+
+    /**
+     * Converts an array of ServiceTypeBase to an array of Class.  If a
+     * class cannot be loaded, it is left as null.
+     */
+    public static Class[] toClass( ServiceTypeBase[] stypes )
+    {
+        Class[] classes = null;
+        if( stypes != null )
+        {
+            classes = new Class[stypes.length];
+            for( int i = stypes.length; --i >= 0; )
+            {
+                try
+                {
+                    ServiceTypeBase stype = stypes[ i ];
+                    classes[ i ] = stype.type.toClass( stype.codebase );
+                }
+                catch( Throwable e )
+                {
+                    RegistrarProxy.handleException( e );
+                }
+            }
+        }
+        return classes;
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Template.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Template.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Template.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Template.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,71 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceTemplate;
+
+/**
+ * A Template contains the fields of a ServiceTemplate packaged up for
+ * transmission between client-side proxies and the registrar server.
+ * Instances are never visible to clients, they are private to the
+ * communication between the proxies and the server.
+ * <p>
+ * This class only has a bare minimum of methods, to minimize
+ * the amount of code downloaded into clients.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class Template implements Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * ServiceTemplate.serviceID
+     *
+     * @serial
+     */
+    public ServiceID serviceID;
+    /**
+     * ServiceTemplate.serviceTypes converted to ServiceTypes
+     *
+     * @serial
+     */
+    public ServiceType[] serviceTypes;
+    /**
+     * ServiceTemplate.attributeSetTemplates converted to EntryReps
+     *
+     * @serial
+     */
+    public EntryRep[] attributeSetTemplates;
+
+    /**
+     * Converts a ServiceTemplate to a Template.  Any exception that results
+     * is bundled up into a MarshalException.
+     */
+    public Template( ServiceTemplate tmpl ) throws RemoteException
+    {
+        serviceID = tmpl.serviceID;
+        serviceTypes = ClassMapper.toServiceType( tmpl.serviceTypes );
+        attributeSetTemplates =
+            EntryRep.toEntryRep( tmpl.attributeSetTemplates, false );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/TransientRegistrarImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/TransientRegistrarImpl.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/TransientRegistrarImpl.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/TransientRegistrarImpl.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,40 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import com.sun.jini.start.LifeCycle;
+
+/**
+ * Class for starting transient lookup services.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class TransientRegistrarImpl extends RegistrarImpl
+{
+
+    /**
+     * Constructs a TransientRegistrarImpl based on a configuration obtained
+     * using the provided arguments.  If lifeCycle is non-null, then its
+     * unregister method is invoked during service shutdown.
+     */
+    TransientRegistrarImpl( String[] configArgs, LifeCycle lifeCycle )
+        throws Exception
+    {
+        super( configArgs, null, false, lifeCycle );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Util.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Util.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Util.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/Util.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,75 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.lookup.ServiceID;
+
+/**
+ * Miscellaneous common utility methods.
+ *
+ * @author Sun Microsystems, Inc.
+ */
+class Util
+{
+
+    /**
+     * Returns Method object for specified method, which should always exist.
+     */
+    static Method getMethod( Class type, String name, Class[] paramTypes )
+    {
+        try
+        {
+            return type.getMethod( name, paramTypes );
+        }
+        catch( NoSuchMethodException e )
+        {
+            throw new AssertionError( e );
+        }
+    }
+
+    /**
+     * Checks if the value of the given service ID to register conforms to the
+     * ServiceID specification, logging a message to the provided logger at the
+     * specified logging level if it doesn't.
+     */
+    static void checkRegistrantServiceID( ServiceID serviceID,
+                                          Logger logger,
+                                          Level level )
+    {
+        if( logger.isLoggable( level ) )
+        {
+            int variant =
+                (int) ( serviceID.getLeastSignificantBits() >> 62 ) & 0x3;
+            if( variant != 2 )
+            {
+                logger.log( level, "{0} has invalid variant {1}",
+                            new Object[]{ serviceID, new Integer( variant ) } );
+            }
+            int version =
+                (int) ( serviceID.getMostSignificantBits() >> 12 ) & 0xF;
+            if( !( version == 1 || version == 4 ) )
+            {
+                logger.log( level, "{0} has invalid version {1}",
+                            new Object[]{ serviceID, new Integer( version ) } );
+            }
+        }
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/UuidGenerator.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/UuidGenerator.java?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/UuidGenerator.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/UuidGenerator.java Tue Dec  9 21:14:30 2008
@@ -0,0 +1,55 @@
+/*
+ * 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 com.sun.jini.reggie;
+
+import net.jini.id.Uuid;
+import net.jini.id.UuidFactory;
+
+/**
+ * Class for generating {@link Uuid} instances.  By default, Reggie uses
+ * instances of this class to generate <code>Uuid</code>s; this behavior can be
+ * customized by providing as configuration entry values instances of
+ * subclasses which override the {@link #generate} method of this class.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class UuidGenerator
+{
+
+    /**
+     * Creates new <code>UuidGenerator</code> instance.
+     */
+    public UuidGenerator()
+    {
+    }
+
+    /**
+     * Generates a new <code>Uuid</code>.  The default implementation of this
+     * method returns the result of calling {@link UuidFactory#generate};
+     * subclasses can override this method to customize <code>Uuid</code>
+     * generation.
+     *
+     * @return newly generated <code>Uuid</code>
+     */
+    // REMIND: accept last generated Uuid as input, for stateful generators?
+    public Uuid generate()
+    {
+        return UuidFactory.generate();
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/build.xml
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/build.xml?rev=724980&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/build.xml (added)
+++ incubator/river/jtsk/skunk/niclas1/services/reggie/src/main/java/com/sun/jini/reggie/build.xml Tue Dec  9 21:14:30 2008
@@ -0,0 +1,255 @@
+<!--
+ ! 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.
+ !-->
+
+<project name="reggie" basedir="." default="all">
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## ENVIRONMENT SETTINGS						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <property name="top" location="../../../../.."/>
+
+  <property name="pkg-path" value="com/sun/jini/${ant.project.name}"/>
+
+  <!-- ##								-->
+  <!-- ## Set java-source for use with the javac task:			-->
+  <!-- ##								-->
+
+  <property name="java-source" value="${pkg-path}/**/*.java"/>
+
+  <import file="${top}/build_common.xml"/>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: all							-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="all"
+          description=""
+          depends="compile,
+		   this.stubs">
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##                                                               -->
+  <!-- ## TARGET: clean                                                 -->
+  <!-- ##                                                               -->
+  <!-- ################################################################ -->
+
+  <target name="clean"
+          description="Removes all files and dirs created by the build."
+          depends="clean.jre.ext">
+
+    <delete dir="${build.classes}/${pkg-path}" quiet="true"/>
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: this.jars						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="this.jars"
+          depends="reggie.jar,
+		   reggie-dl.jar">
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: reggie.jar						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="reggie.jar"
+          depends="tools">
+
+    <property name="reggie.deps" location="${build.deps}/reggie.deps"/>
+
+    <!-- ##								-->
+    <!-- ## Run ClassDep.						-->
+    <!-- ##								-->
+
+    <java classname="com.sun.jini.tool.ClassDep"
+          failonerror="true"
+          output="${reggie.deps}">
+
+      <classpath refid="path.classdep"/>
+      <arg value="-cp"/>
+      <arg path="${build.classes}"/>
+      <arg value="-files"/>
+      <arg line="${jskprivate.include}"/>
+
+      <arg line="-in com.sun.jini.reggie"/>
+
+      <arg value="com.sun.jini.reggie.PersistentRegistrarImpl"/>
+      <arg value="com.sun.jini.reggie.RegistrarPermission"/>
+      <arg value="com.sun.jini.reggie.RegistrarImpl_Stub"/>
+      <arg value="com.sun.jini.reggie.TransientRegistrarImpl"/>
+
+    </java>
+
+    <!-- ##								-->
+    <!-- ## Generate the jar file.					-->
+    <!-- ##								-->
+
+    <delete file="${build.lib}/reggie.jar" quiet="true"/>
+
+    <jar destfile="${build.lib}/reggie.jar"
+         index="false"
+         manifest="${src.jini.manifest}/reggie.mf">
+
+      <fileset dir="${build.classes}" includesfile="${reggie.deps}"/>
+
+    </jar>
+
+    <!-- ##								-->
+    <!-- ## Generate the Preferred List					-->
+    <!-- ##								-->
+
+    <preferredlistgen>
+
+      <plg-elements>
+
+        <arg line="-cp"/>
+        <arg path="${build.classes}"/>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib}/reggie.jar"/>
+
+        <arg line="-default true"/>
+
+      </plg-elements>
+
+    </preferredlistgen>
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: reggie-dl.jar						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="reggie-dl.jar"
+          depends="tools">
+
+    <property name="reggie-dl.deps" location="${build.deps}/reggie-dl.deps"/>
+
+    <!-- ##								-->
+    <!-- ## Run ClassDep.						-->
+    <!-- ##								-->
+
+    <java classname="com.sun.jini.tool.ClassDep"
+          failonerror="true"
+          output="${reggie-dl.deps}">
+
+      <classpath refid="path.classdep"/>
+      <arg value="-cp"/>
+      <arg path="${build.classes}"/>
+      <arg value="-files"/>
+      <arg line="${jskprivate.include}"/>
+
+      <arg line="-in com.sun.jini.reggie"/>
+
+      <arg value="com.sun.jini.lookup.entry.BasicServiceType"/>
+      <arg value="com.sun.jini.reggie.AdminProxy"/>
+      <arg value="com.sun.jini.reggie.EventLease"/>
+      <arg value="com.sun.jini.reggie.ProxyVerifier"/>
+      <arg value="com.sun.jini.reggie.RegistrarEvent"/>
+      <arg value="com.sun.jini.reggie.RegistrarImpl_Stub"/>
+      <arg value="com.sun.jini.reggie.RegistrarPermission"/>
+      <arg value="com.sun.jini.reggie.RegistrarProxy"/>
+      <arg value="com.sun.jini.reggie.Registration"/>
+      <arg value="com.sun.jini.reliableLog.LogException"/>
+      <arg value="net.jini.lookup.entry.ServiceInfo"/>
+
+    </java>
+
+    <!-- ##								-->
+    <!-- ## Generate the jar file.					-->
+    <!-- ##								-->
+
+    <delete file="${build.lib-dl}/reggie-dl.jar" quiet="true"/>
+
+    <jar destfile="${build.lib-dl}/reggie-dl.jar"
+         index="false">
+
+      <fileset dir="${build.classes}" includesfile="${reggie-dl.deps}"/>
+
+    </jar>
+
+    <!-- ##								-->
+    <!-- ## Generate the Preferred List					-->
+    <!-- ##								-->
+
+    <preferredlistgen>
+
+      <plg-elements>
+
+        <arg line="-cp"/>
+        <arg path="${build.classes}"/>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib-dl}/reggie-dl.jar"/>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib-dl}/jsk-dl.jar"/>
+
+        <arg line=
+          "-proxy com.sun.jini.reggie.ConstrainableRegistrarProxy"/>
+        <arg line="-proxy com.sun.jini.reggie.ConstrainableAdminProxy"/>
+
+      </plg-elements>
+
+    </preferredlistgen>
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: this.stubs						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="this.stubs"
+          description="Builds the RMI stubs for ${ant.project.name}."
+          depends="compile">
+
+    <rmic base="${build.classes}" stubversion="1.2">
+
+      <classpath refid="path.jini"/>
+      <include name="com/sun/jini/reggie/RegistrarImpl.class"/>
+
+    </rmic>
+
+  </target>
+
+</project>
+



Mime
View raw message