You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by ni...@apache.org on 2008/12/10 06:16:43 UTC

svn commit: r724986 [5/7] - in /incubator/river/jtsk/skunk/niclas1/services/mercury: ./ 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/mercury/ src/main/resources/ src/main...

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventData.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventData.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventData.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventData.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,128 @@
+/*
+ * 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.mercury;
+
+import com.sun.jini.proxy.MarshalledWrapper;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import net.jini.core.event.RemoteEvent;
+import net.jini.io.MarshalledInstance;
+
+/**
+ * Simple struct to hold a <code>RemoteEvent</code> and its associated
+ * <code>Object</code> (cookie) obtained from an <code>EventLog</code>.
+ */
+class RemoteEventData implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * <code>MarshalledObject</code> that holds desired
+     * <code>RemoteEvent</code>. Wrapping the remote event
+     * permits deserialization to occur on demand on the
+     * client-side.
+     */
+    private MarshalledInstance mi;
+
+    /**
+     * Cookie associated with the <code>RemoteEvent</code>
+     */
+    private final Object cookie;
+
+    /**
+     * <code>true</code> if the last time this object was unmarshalled
+     * integrity was being enforced, <code>false</code> otherwise.
+     */
+    private transient boolean integrity;
+
+    /**
+     * Creates a new RemoteEventData instance.
+     *
+     * @param re     value of <code>re</code> field.
+     * @param cookie value of <code>cookie</code> field.
+     */
+    RemoteEventData( RemoteEvent re, Object cookie )
+    {
+        try
+        {
+            mi = ( re == null ) ? null : new MarshalledInstance( re );
+        }
+        catch( IOException ioe )
+        {
+            mi = null;
+        }
+        this.cookie = cookie;
+    }
+
+    public RemoteEvent getRemoteEvent() throws ClassNotFoundException
+    {
+        if( mi == null )
+        {
+            throw new ClassNotFoundException(
+                "Failed to create server-side remote event" );
+        }
+        RemoteEvent re = null;
+        try
+        {
+            re = (RemoteEvent) mi.get( integrity );
+        }
+        catch( IOException ioe )
+        {
+            throw new ClassNotFoundException(
+                "Failed to create client-side remote event", ioe );
+        }
+        return re;
+    }
+
+    public Object getCookie()
+    {
+        return cookie;
+    }
+
+    /**
+     * Use <code>readObject</code> method to capture whether or
+     * not integrity was being enforced when this object was
+     * unmarshalled, and to perform basic integrity checks.
+     */
+    private void readObject( ObjectInputStream in )
+        throws IOException, ClassNotFoundException
+    {
+        in.defaultReadObject();
+
+        if( cookie == null )
+        {
+            throw new InvalidObjectException( "null cookie" );
+        }
+
+        // get value for integrity flag
+        integrity = MarshalledWrapper.integrityEnforced( in );
+    }
+
+    /**
+     * We should always have data in the stream, if this method
+     * gets called there is something wrong.
+     */
+    private void readObjectNoData() throws InvalidObjectException
+    {
+        throw new
+            InvalidObjectException( "RemoteEventData should always have data" );
+    }
+
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventDataCursor.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventDataCursor.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventDataCursor.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventDataCursor.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.mercury;
+
+import java.io.Serializable;
+
+/**
+ * Trivial class (struct) that simply holds the current read count
+ * and the associated (next unread) read position. U?sed as the client-side
+ * cookie for PersistentEventLog.
+ *
+ * @since 2.1
+ */
+class RemoteEventDataCursor implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    private final long readCount;
+    private final long readPosition;
+
+    RemoteEventDataCursor( long count, long cursor )
+    {
+        readCount = count;
+        readPosition = cursor;
+    }
+
+    long getReadCount()
+    {
+        return readCount;
+    }
+
+    long getReadPosition()
+    {
+        return readPosition;
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorData.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorData.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorData.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorData.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.mercury;
+
+import java.io.Serializable;
+import java.util.Collection;
+import net.jini.id.Uuid;
+
+/**
+ * Simple struct to hold the <code>Uuid</code> for a new
+ * <code>RemoteEventIterator</code> instance and the first batch of
+ * data.
+ */
+class RemoteEventIteratorData implements Serializable
+{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * <code>Uuid</code> for iteration.
+     */
+    final Uuid uuid;
+
+    /**
+     * Initial set of entries
+     */
+    final Collection events;
+
+    /**
+     * Creates a new RemoteEventIteratorData instance.
+     *
+     * @param uuid                value of <code>uuid</code> field.
+     * @param reps                value of <code>events</code> field.
+     * @param intialLeaseDuration value of <code>intialLeaseDuration</code>
+     *                            field.
+     */
+    RemoteEventIteratorData( Uuid uuid, Collection events )
+    {
+        this.uuid = uuid;
+        this.events = events;
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorImpl.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorImpl.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/RemoteEventIteratorImpl.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,203 @@
+/*
+ * 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.mercury;
+
+import com.sun.jini.proxy.ThrowThis;
+import java.rmi.RemoteException;
+import java.util.Collection;
+import java.util.Iterator;
+import net.jini.core.event.RemoteEvent;
+import net.jini.event.InvalidIteratorException;
+import net.jini.event.RemoteEventIterator;
+import net.jini.id.Uuid;
+
+/**
+ * @author Sun Microsystems, Inc.
+ * @since 1.1
+ */
+class RemoteEventIteratorImpl implements RemoteEventIterator
+{
+    /**
+     * Unique identifier for this registration
+     */
+    final Uuid registrationID;
+
+    /**
+     * Unique identifier for this registration
+     */
+    final Uuid iteratorID;
+
+    /**
+     * Reference to service implementation
+     */
+    final MailboxBackEnd mailbox;
+
+    /**
+     * Event iterator *
+     */
+    private Iterator iter = null;
+
+    /**
+     * Last remote event cookie
+     */
+    private Object lastEventCookie = null;
+
+    /**
+     * lock object protecting <code>invalidated</code> flag.
+     */
+    private Object invalidatedLock = new Object();
+
+    /**
+     * Boolean flag indicating the (in)validity of this object.
+     * If true, the object is invalid and all public method invocations
+     * should throw InvalidIteratorException.
+     */
+    private boolean invalidated = false;
+
+    /**
+     * Convenience constructor
+     */
+    RemoteEventIteratorImpl( Uuid id, Uuid regId, MailboxBackEnd srv,
+                             Collection evts )
+    {
+        if( id == null || regId == null || srv == null || evts == null )
+        {
+            throw new IllegalArgumentException( "Cannot accept null arguments" );
+        }
+        registrationID = regId;
+        iteratorID = id;
+        mailbox = srv;
+        iter = evts.iterator();
+    }
+
+    // inherit javadoc from supertype
+    public RemoteEvent next( long timeout )
+        throws RemoteException, InvalidIteratorException
+    {
+        //TODO - implement timeout
+        //TODO - handle ClassNotFoundException for getRemoteEvent() call
+        checkState();
+
+        if( timeout < 0 )
+        {
+            throw new
+                IllegalArgumentException( "Timeout value must non-negative" );
+        }
+
+        RemoteEvent re = null;
+        LocalRemoteEventData lred = getNextValidLocalRemoteEventData( iter );
+        if( lred != null )
+        {
+            re = lred.re;
+            lastEventCookie = lred.cookie;
+        }
+        else
+        { // get next batch of events, if any
+            try
+            {
+                Collection events =
+                    mailbox.getNextBatch(
+                        registrationID, iteratorID, timeout,
+                        lastEventCookie );
+                iter = events.iterator();
+                lred = getNextValidLocalRemoteEventData( iter );
+                if( lred != null )
+                {
+                    re = lred.re;
+                    lastEventCookie = lred.cookie;
+                }
+            }
+            catch( InvalidIteratorException iie )
+            {
+                invalidate();
+                throw iie;
+            }
+            catch( ThrowThis tt )
+            {
+                tt.throwRemoteException();
+            }
+        }
+        return re;
+    }
+
+    private static class LocalRemoteEventData
+    {
+        RemoteEvent re = null;
+        Object cookie = null;
+
+        LocalRemoteEventData( RemoteEvent re, Object cookie )
+        {
+            this.re = re;
+            this.cookie = cookie;
+        }
+    }
+
+    private LocalRemoteEventData getNextValidLocalRemoteEventData( Iterator i )
+    {
+        RemoteEventData rd = null;
+        LocalRemoteEventData lrd = null;
+        try
+        {
+            if( i != null && i.hasNext() )
+            {
+                rd = (RemoteEventData) i.next();
+                lrd = new LocalRemoteEventData(
+                    rd.getRemoteEvent(), rd.getCookie() );
+            }
+        }
+        catch( ClassNotFoundException cnfe )
+        {
+            lrd = getNextValidLocalRemoteEventData( i );
+        }
+
+        return lrd;
+    }
+
+    // inherit javadoc from supertype
+    public void close() throws InvalidIteratorException
+    {
+        checkState();
+        invalidate();
+    }
+
+    /**
+     * Utility method that checks the validity of this object
+     * and throws an exception if it's invalid.
+     */
+    private void checkState() throws InvalidIteratorException
+    {
+        synchronized( invalidatedLock )
+        {
+            if( invalidated )
+            {
+                throw new InvalidIteratorException();
+            }
+        }
+    }
+
+    /**
+     * Utility method that marks this object as invalid.
+     */
+    private void invalidate()
+    {
+        synchronized( invalidatedLock )
+        {
+            invalidated = true;
+        }
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/ServiceRegistration.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/ServiceRegistration.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/ServiceRegistration.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/ServiceRegistration.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,328 @@
+/*
+ * 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.mercury;
+
+import com.sun.jini.landlord.LeasedResource;
+import java.io.IOException;
+import java.io.Serializable;
+import java.rmi.MarshalledObject;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.event.RemoteEventListener;
+import net.jini.id.Uuid;
+import net.jini.security.ProxyPreparer;
+
+/**
+ * The <tt>ServiceRegistration</tt> class serves as the server-side abstraction
+ * that maintains client registration state information. It implements the
+ * <tt>LeasedResource</tt> interface to allow it to be used with the
+ * <tt>Landlord</tt> framework. It implements the <tt>Comparable</tt>
+ * interface so that it can be used in <tt>SortedMap</tt> collections.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 1.1
+ */
+class ServiceRegistration implements LeasedResource, Comparable, Serializable
+{
+
+    private static final long serialVersionUID = 2L;
+
+    /**
+     * Unique identifier object
+     */
+    private final Uuid cookie;
+
+    /**
+     * The current expiration for this registration
+     */
+    private long expiration = 0;
+
+    /**
+     * The prepared, client-provided notification target.
+     */
+    // This field is transient in order to allow readObject/writeObject
+    // to un/wrap the the listener to/from a MarshalledObject. 
+    // This is done to prevent the corruption of the input stream.
+    // For example, if the associated codebase of the listener object
+    // is no longer valid, then the stream is corrupted since the object
+    // can't be reconstructed.  Wrapping the reference in a 
+    // MarshalledObject always allows us to read from the stream.
+    // We might not be able to reconstruct the listener field, but
+    // the rest of the objects in the stream will be fine.
+    private transient RemoteEventListener preparedEventTarget = null;
+
+    /**
+     * The marshalled form of the client-provided notification target.
+     */
+    private MarshalledObject marshalledEventTarget = null;
+
+    /**
+     * Event log iterator.
+     */
+    // This field is transient because event state info is persisted
+    // separately from the registration state info. It is (re)constructed
+    // upon service initialization.
+    private transient EventLogIterator eventIterator = null;
+
+    /**
+     * Map of collected <tt>EventID</tt>'s that resulted in an
+     * UnknownEventException for the current <code>
+     * eventTarget</code>. This <code>Map</code> is checked
+     * upon each mailbox notification for this registration.
+     * If the received event has the same <tt>EventID</tt>
+     * as the one contained in this <code>Map</code> then an
+     * <code>UnknownEventException</code>
+     * is propagated back to the sender and the event is not logged.
+     * This structure is also consulted before each event delivery request.
+     * If the event to be delivered has an <tt>EventID</tt> that is
+     * contained in this <tt>Map</tt>, then event delivery is cancelled
+     * for that particular event. Note that this structure gets cleared
+     * whenever a target listener is (re)set on the assumption that an
+     * active (re)set will provide a new/better target listener that might
+     * be able to handle these events.
+     */
+    private Map unknownEvents = new HashMap();
+
+    /**
+     * Unique identifier object for the currently enabled
+     * (client-side) remote event iterator.
+     */
+    private Uuid remoteEventIteratorID;
+
+    /**
+     * Lock object used to coordinate event delivery via the iterator.
+     * Has to be a serializable object versus just a plain Object.
+     */
+    private final String iteratorNotifier = new String();
+
+
+    /**
+     * Convenience constructor
+     */
+    public ServiceRegistration( Uuid cookie, EventLogIterator eventIterator )
+    {
+        this.cookie = cookie;
+        this.eventIterator = eventIterator;
+    }
+
+    // inherit javadoc from parent
+    public void setExpiration( long newExpiration )
+    {
+        expiration = newExpiration;
+    }
+
+    // inherit javadoc from parent
+    public long getExpiration()
+    {
+        return expiration;
+    }
+
+    // inherit javadoc from parent
+    public Uuid getCookie()
+    {
+        return cookie;
+    }
+
+    /**
+     * Return the identity map of EventIDs that caused an
+     * UnknownEventException to be generated for the current
+     * notification target. A Map is used instead of a generic
+     * Collection since the space/time tradeoff for searches
+     * seems worth it.
+     */
+    public Map getUnknownEvents()
+    {
+        return unknownEvents;
+    }
+
+    /**
+     * Get the reference to the prepared,
+     * client-supplied notification target
+     */
+    public RemoteEventListener getEventTarget()
+    {
+        return preparedEventTarget;
+
+    }
+
+    /**
+     * Set the reference to the client-supplied notification target
+     */
+    public void setEventTarget( RemoteEventListener preparedTarget )
+        throws IOException
+    {
+        if( preparedTarget == null )
+        {
+            preparedEventTarget = null;
+            marshalledEventTarget = null;
+        }
+        else
+        {
+            preparedEventTarget = preparedTarget;
+            marshalledEventTarget = new MarshalledObject( preparedTarget );
+        }
+    }
+
+    /**
+     * Get the remote iterator id
+     */
+    public Uuid getRemoteEventIteratorID()
+    {
+        return remoteEventIteratorID;
+    }
+
+    /**
+     * Get the remote iterator notifier object. This is used to coordinate
+     * notifications between event delivery and event reception via the
+     * iterator.
+     */
+    public Object getIteratorNotifier()
+    {
+        return iteratorNotifier;
+    }
+
+    /**
+     * Set the remote iterator id
+     */
+    public void setRemoteEventIteratorID( Uuid id )
+    {
+        remoteEventIteratorID = id;
+
+    }
+
+    /**
+     * Returns <code>true</code> if an event target is currently set and
+     * false otherwise.
+     */
+    public boolean hasEventTarget()
+    {
+        return ( marshalledEventTarget != null );
+    }
+
+    /*
+    * Method that restores internal, transient state.
+    * Note:
+    * This method attempts to prepare the target listener object, which
+    * might involve a remote invocation. Therefore, calling this method
+    * while holding a lock should be avoided.
+    */
+    public void restoreTransientState( ProxyPreparer targetPreparer )
+        throws IOException, ClassNotFoundException
+    {
+        if( targetPreparer == null )
+        {
+            throw new NullPointerException(
+                "targetPreparer cannot be null" );
+        }
+        if( marshalledEventTarget != null )
+        {
+            RemoteEventListener unprepared =
+                (RemoteEventListener) marshalledEventTarget.get();
+            preparedEventTarget = (RemoteEventListener)
+                targetPreparer.prepareProxy( unprepared );
+        }
+        /*
+       * Note: Would like to defer preparation until listener
+       * is needed (i.e. in getEventTarget()). Unfortunately,
+       * listeners are obtained within "locks" and proxy
+       * preparation (i.e. possible remote calls) should
+       * not be done while holding those locks.
+       */
+    }
+
+    /**
+     * Get the  reference to the registration's associated
+     * <tt>EventLogIterator</tt>
+     */
+    public EventLogIterator iterator()
+    {
+        return eventIterator;
+    }
+
+    /**
+     * Set the reference for this registration's
+     * <tt>EventLogIterator</tt>
+     */
+    public void setIterator( EventLogIterator iter )
+    {
+        eventIterator = iter;
+    }
+
+    /**
+     * Primary sort by leaseExpiration, secondary by leaseID.  The
+     * secondary sort is immaterial, except to ensure a total order
+     * (required by TreeMap).
+     */
+    public int compareTo( Object obj )
+    {
+        ServiceRegistration reg = (ServiceRegistration) obj;
+        if( this == reg )
+        {
+            return 0;
+        }
+        if( expiration < reg.expiration ||
+            ( expiration == reg.expiration &&
+              ( ( cookie.getMostSignificantBits() <
+                  reg.cookie.getMostSignificantBits() )
+                && ( cookie.getLeastSignificantBits() <
+                     reg.cookie.getLeastSignificantBits() ) ) ) )
+        {
+            return -1;
+        }
+        return 1;
+    }
+
+    // inherit documentation from supertype
+    public String toString()
+    {
+        return getClass().getName() + ":" + cookie.toString();
+    }
+
+//TODO - implement readObject() for structural checks
+
+    /**
+     * Utility method to display debugging information to the
+     * provided <tt>Logger</tt>
+     */
+    void dumpInfo( Logger logger )
+    {
+        logger.log( Level.FINEST, "{0}", this.toString() );
+        logger.log( Level.FINEST, "Expires at: {0}", new Date( expiration ) );
+        logger.log( Level.FINEST, "Prepared target is: {0}", preparedEventTarget );
+        logger.log( Level.FINEST, "Marshalled target is: {0}", marshalledEventTarget );
+        logger.log( Level.FINEST, "Unknowns: {0}",
+                    new Integer( unknownEvents.size() ) );
+        // eventIterator is null upon recovery phase  which
+        // is before the transient state gets rebuilt.
+        if( eventIterator != null )
+        {
+            try
+            {
+                logger.log( Level.FINEST, "hasNext: {0}",
+                            Boolean.valueOf( eventIterator.hasNext() ) );
+            }
+            catch( IOException ioe )
+            {
+                logger.log( Level.FINEST, "hasNext exception.", ioe );
+            }
+        }
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamKey.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamKey.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamKey.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamKey.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.mercury;
+
+import java.io.File;
+
+/**
+ * Class used as the key value for an associated <tt>LogStream</tt> object in
+ * a collection of type <tt>java.util.Map</tt>.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 1.1
+ */
+class StreamKey
+{
+
+    /**
+     * Holds the <tt>File</tt> attribute for the associated stream.
+     */
+    private /*final*/ File file;
+
+    /**
+     * Holds the "enumeration" type for the associated stream.
+     */
+    private /*final*/ StreamType type;
+
+    /**
+     * Holds the cached value of the <tt>file</tt> field's hashCode.
+     */
+    private /*final*/ int hash;
+
+    /**
+     * Simple constructor that accepts <tt>File</tt> and <tt>StreamType</tt>
+     * arguments and then assigns them to the appropriate internal fields.
+     * Neither argument can be <code>null</code>. The <tt>File</tt>
+     * argument must represent an absolute pathname.
+     *
+     * @throws IllegalArgumentException thrown if either of the arguments are
+     *                                  null or if the <tt>file</tt>
+     *                                  argument does not represent an
+     *                                  absolute pathname.
+     */
+
+    StreamKey( File file, StreamType type )
+    {
+        if( file == null || type == null )
+        {
+            throw new IllegalArgumentException( "Cannot use <null> for " +
+                                                "path or type arguments." );
+        }
+
+        // Note: relative and absolute paths to the same file
+        // are not considered equal. Therefore, we ensure that all 
+        // file arguments are absolute so that <tt>equals</tt> behaves
+        // as expected.
+        if( !file.isAbsolute() )
+        {
+            throw new IllegalArgumentException( "Cannot use a relative path " +
+                                                "for the <file> argument" );
+        }
+        this.file = file;
+        this.type = type;
+        this.hash = file.hashCode(); //cache it since it won't change
+    }
+
+    /* Inherit javadoc from supertype */
+    public int hashCode()
+    {
+        return hash;
+    }
+
+    /* Inherit javadoc from supertype */
+    public boolean equals( Object o )
+    {
+        if( this == o )
+        {
+            return true;
+        }
+
+        if( o == null )
+        {
+            return false;
+        }
+
+        if( o.getClass() != getClass() )
+        {
+            return false;
+        }
+
+        StreamKey sk = (StreamKey) o;
+        return ( ( type == sk.type ) && ( file.equals( sk.file ) ) );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamPool.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamPool.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamPool.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamPool.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,354 @@
+/*
+ * 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.mercury;
+
+import com.sun.jini.logging.Levels;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class provides a pool of <tt>LogStream</tt> objects.  Each
+ * <tt>LogStream</tt> has an associated <tt>FileDescriptor</tt>, which
+ * is the system resource we are trying to manage. This pool limits the
+ * (user configurable) number of concurrent, open <tt>FileDescriptor</tt>s.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 1.1
+ */
+class StreamPool
+{
+    // Class fields
+    /**
+     * Logger for lease related messages
+     */
+    private static final Logger persistenceLogger =
+        MailboxImpl.persistenceLogger;
+
+    /**
+     * Maximum limit for the number of concurrent <tt>LogStream</tt>s
+     * in the stream pool.
+     */
+    private final int maxPoolSize;
+
+    /**
+     * Holds stream references by associated key
+     */
+    private final HashMap pool;
+
+    /**
+     * Holds stream references in least recently used (released) order.
+     * It's used in order determine which stream to discard upon
+     * reaching the maximum pool limit.
+     */
+    private final LinkedList freeList;
+
+    /**
+     * Simple constructor that creates a pool of given <code>size</code>.
+     *
+     * @throws IllegalArgumentException Thrown if the value of
+     *                                  <tt>maxPoolSize</tt> is less than 1.
+     */
+    StreamPool( int size )
+    {
+        if( size < 1 )
+        {
+            throw new IllegalArgumentException(
+                "Pool size must be greater than 0." );
+        }
+        maxPoolSize = size;
+        pool = new HashMap( maxPoolSize );
+        freeList = new LinkedList();
+
+        if( persistenceLogger.isLoggable( Level.FINEST ) )
+        {
+            persistenceLogger.log( Level.FINEST,
+                                   "Created StreamPool of size {0}",
+                                   new Integer( maxPoolSize ) );
+        }
+    }
+
+    /**
+     * Returns a <tt>ControlLog</tt> object for the specified <tt>file</tt>
+     * from the pool if it already exists.
+     * Otherwise, it creates a new instance and adds it to the pool.
+     *
+     * @throws IOException if an I/O error occurs
+     */
+    synchronized ControlLog getControlLog( File file )
+        throws IOException
+    {
+        StreamKey key = new StreamKey( file, StreamType.CONTROL );
+        ControlLog log = (ControlLog) pool.get( key );
+        if( log != null )
+        { // found it!
+            if( freeList.remove( key ) == false )
+            {
+                throw new InternalMailboxException( "Did not find re-used control log "
+                                                    + "stream in freeList." );
+            }
+        }
+        else
+        { // Log was not found, so attempt to add it
+
+            ensurePoolSpace();
+
+            //
+            // Create new ControlLog and add it the pool.
+            //
+            log = new ControlLog( file, key );
+            pool.put( key, log );
+
+            if( freeList.remove( key ) )
+            {
+                throw new InternalMailboxException( "Found newly created ControlLog "
+                                                    + "in freeList" );
+            }
+        }
+
+        return log;
+    }
+
+    /**
+     * Returns a <tt>LogInputStream</tt> object from the pool if it
+     * already exists. Otherwise, it creates a new instance and adds
+     * it to the pool.
+     *
+     * @throws IOException if an I/O error occurs
+     */
+    synchronized LogInputStream getLogInputStream( File file, long offset )
+        throws IOException
+    {
+        StreamKey key = new StreamKey( file, StreamType.INPUT );
+        LogInputStream in = (LogInputStream) pool.get( key );
+        if( in != null )
+        { //found it!
+            if( freeList.remove( key ) == false )
+            {
+                throw new InternalMailboxException( "Did not find re-used input log "
+                                                    + "stream in freelist." );
+            }
+        }
+
+        if( in == null ||            // if log not found OR
+            in.getOffset() > offset ) // current read offset is past desired
+        {                            // then create a new log and add it
+            ensurePoolSpace();
+
+            in = new LogInputStream( file, key );
+            pool.put( key, in );
+
+            if( freeList.remove( key ) )
+            {
+                throw new InternalMailboxException( "Found newly created ControlLog "
+                                                    + "on freeList" );
+            }
+        }
+
+        // Sanity check for offset value
+        if( offset > file.length() )
+        {
+            throw new EOFException( "Attempting to read past end of file." );
+        }
+
+        // Check if log offset needs adjusting.
+        // By this point in.offset <= offset.
+        while( in.getOffset() < offset )
+        {
+            in.skip( offset - in.getOffset() );
+        }
+
+        return in;
+    }
+
+    /**
+     * Returns a <tt>LogOutputStream</tt> object for the specified <tt>file</tt>
+     * from the pool if it already exists.
+     * Otherwise, it creates a new instance and adds it to the pool.
+     *
+     * @throws IOException if an I/O error occurs
+     */
+    synchronized LogOutputStream getLogOutputStream( File file, long offset )
+        throws IOException
+    {
+        StreamKey key = new StreamKey( file, StreamType.OUTPUT );
+        LogOutputStream out = (LogOutputStream) pool.get( key );
+
+        if( out != null )
+        { // found it!
+            if( freeList.remove( key ) == false )
+            {
+                throw new InternalMailboxException( "Did not find re-used output log "
+                                                    + "stream in freelist" );
+            }
+
+            // Sanity check to see if we are still in sync. If not,
+            // then we need to close this stream and create another
+            // one (done in the next code block).
+            if( out.getOffset() != offset )
+            {
+                removeLogStream( out );
+                out = null;
+            }
+        }
+
+        // Check to see if we need to create another log.
+        if( out == null )
+        {
+
+            ensurePoolSpace();
+
+            if( offset == 0L )
+            { // Create new log, without appending
+                out = new LogOutputStream( file, key, false );
+            }
+            else
+            { // Create new log, appending to existing file
+                long len = file.length();
+
+                if( offset > len )
+                {
+                    throw new EOFException( "Attempting to write past end "
+                                            + "of file" );
+                }
+
+                if( offset < len )
+                {
+                    RandomAccessFile raf = new RandomAccessFile( file, "rw" );
+                    raf.setLength( offset );
+                    raf.close();
+                }
+
+                out = new LogOutputStream( file, key, true );
+            }
+
+            pool.put( key, out );
+
+            if( freeList.remove( key ) )
+            {
+                throw new InternalMailboxException( "Found newly created output log "
+                                                    + "in freeList" );
+            }
+
+        }
+
+        return out;
+    }
+
+    /**
+     * Ensures that room is available in the pool. If the pool is currently
+     * full, then the least recently used <tt>LogStream</tt> will be removed
+     * and closed to make room. This method will block if the pool is full and
+     * no <tt>LogStream</tt> objects can be closed.
+     *
+     * @throws IOException if an I/O error occurs
+     */
+    private synchronized void ensurePoolSpace() throws IOException
+    {
+        if( pool.size() >= maxPoolSize )
+        {
+            while( freeList.size() < 1 )
+            {
+                try
+                {
+                    wait();
+                }
+                catch( InterruptedException ie )
+                {
+                    ;
+                }
+            }
+            StreamKey key = (StreamKey) freeList.removeFirst();
+            LogStream els = (LogStream) pool.remove( key );
+            els.close();
+        }
+    }
+
+    /**
+     * Marks a stream as available for closing.
+     * A log will only be closed if a new log is requested and the
+     * pool has reached its maximum size.
+     */
+    synchronized void releaseLogStream( LogStream stream )
+    {
+        StreamKey key = (StreamKey) stream.getKey();
+        if( pool.get( key ) == null )
+        {
+            throw new InternalMailboxException( "Not managing stream: "
+                                                + stream + ":" + key + " -- release failed" );
+        }
+        freeList.add( key );
+        notifyAll();
+    }
+
+    /**
+     * Removes the given <tt>LogStream</tt> from the pool and closes it,
+     * if possible. The intent is for this method to be called for
+     * unusable logs so that they will no longer be returned by a
+     * subsequent call to one of the "get" methods.
+     */
+    synchronized void removeLogStream( LogStream stream )
+    {
+        StreamKey key = (StreamKey) stream.getKey();
+        if( pool.remove( key ) == null )
+        {
+            throw new InternalMailboxException( "Not managing stream: "
+                                                + stream + ":" + key + " -- remove failed" );
+        }
+
+        // Remove it from freeList, if present
+        freeList.remove( key );
+        try
+        {
+            stream.close();
+        }
+        catch( IOException ioe )
+        {
+            // Note the exception, but otherwise ignore
+            if( persistenceLogger.isLoggable( Levels.HANDLED ) )
+            {
+                persistenceLogger.log( Levels.HANDLED,
+                                       "Exception closing Log", ioe );
+            }
+        }
+    }
+
+    //
+    // Debug use only!
+    //
+    synchronized int getPoolSize()
+    {
+        return pool.size();
+    }
+
+    synchronized int getFreeSize()
+    {
+        return freeList.size();
+    }
+
+    synchronized void dump()
+    {
+        System.out.println( "Pool:\n" + pool );
+        System.out.println( "Free:\n" + freeList );
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamType.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamType.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamType.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/StreamType.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.mercury;
+
+/**
+ * Class that serves the purpose of an enumeration type. It's used
+ * in conjunction with <tt>StreamKey</tt> in order to distinguish among
+ * different <tt>LogStream</tt> objects that can potentially act upon the
+ * same underlying log file.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 1.1
+ */
+class StreamType
+{
+
+    /**
+     * Simple constructor. Private protection is used in order to prevent
+     * external instantiation of this class type.
+     */
+    private StreamType()
+    {
+        ;
+    }
+
+    /**
+     * Event data output stream enumeration
+     */
+    static final StreamType OUTPUT = new StreamType();
+
+    /**
+     * Event data input stream enumeration
+     */
+    static final StreamType INPUT = new StreamType();
+
+    /**
+     * Control data stream enumeration. Control data will not use
+     * separate input/output data streams and therefore no distinction
+     * is made.
+     */
+    static final StreamType CONTROL = new StreamType();
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientEventLog.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientEventLog.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientEventLog.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientEventLog.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,342 @@
+/*
+ * 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.mercury;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.core.event.RemoteEvent;
+import net.jini.id.Uuid;
+
+/**
+ * Class that implements the interface for an <tt>EventLog</tt>.
+ * This class encapsulates the details of reading/writing events from/to
+ * some non-persistent mechanism.
+ *
+ * This class makes certain assumptions. First, the <tt>next</tt> and
+ * <tt>remove</tt> methods are intended to be called in pairs. If
+ * <tt>remove</tt> is not called, then subsequent calls to <tt>next</tt>
+ * will attempt to return the same object. Calling <tt>remove</tt>
+ * essentially advances the read pointer to the next object, if any.
+ *
+ * There is also an implicit assumption of external synchronization by the
+ * caller. That is, only one calling thread will be accessing the log at a time.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+
+class TransientEventLog implements EventLog
+{
+
+    //
+    // Class fields
+    //
+
+    /**
+     * <tt>Logger</tt> used for persistence-related debugging messages
+     */
+    private static final Logger persistenceLogger =
+        MailboxImpl.persistenceLogger;
+
+    //
+    // Object fields
+    //
+
+    /**
+     * The associated <tt>Uuid</tt> for this <tt>EventLog</tt>.
+     */
+    private Uuid uuid = null;
+
+    /**
+     * The associated, non-persistent storage for events
+     */
+    private List entries = null;
+
+    /**
+     * Flag that is used to determine whether or not this object
+     * has been closed.
+     */
+    private boolean closed = false;
+
+    /**
+     * Flag that is used to determine whether or not this object
+     * has been initialized.
+     */
+    private boolean initialized = false;
+
+    /**
+     * Helper class used to hold a remote event and a sequence id.
+     */
+    private static class RemoteEventHolder
+    {
+        private final long id;
+        private final RemoteEvent remoteEvent;
+
+        RemoteEventHolder( long stamp, RemoteEvent re )
+        {
+            id = stamp;
+            remoteEvent = re;
+        }
+
+        long getID()
+        {
+            return id;
+        }
+
+        RemoteEvent getRemoteEvent()
+        {
+            return remoteEvent;
+        }
+    }
+
+    /**
+     * Counter used to produce event ids.
+     */
+    private long eventCounter = 1L;
+
+    /**
+     * Simple constructor that takes a <tt>Uuid</tt> argument.
+     *
+     * @throws IllegalArgumentException if the argument is null
+     */
+    TransientEventLog( Uuid uuid )
+    {
+        if( uuid == null )
+        {
+            throw new IllegalArgumentException( "Uuid cannot be null" );
+        }
+        this.uuid = uuid;
+        entries = Collections.synchronizedList( new LinkedList() );
+
+        if( persistenceLogger.isLoggable( Level.FINEST ) )
+        {
+            persistenceLogger.log( Level.FINEST,
+                                   "TransientEventLog for: {0}", uuid );
+        }
+    }
+
+    // Inherit documentation from supertype
+    public void init() throws IOException
+    {
+        if( initialized )
+        {
+            throw new InternalMailboxException(
+                "Trying to re-initialize event log "
+                + "for: " + uuid );
+        }
+        initialized = true;
+    }
+
+    /**
+     * Asserts that the log is in a valid state.
+     *
+     * @throws IOException if the log is in an invalid state
+     */
+    private void stateCheck() throws IOException
+    {
+        if( !initialized )
+        {
+            throw new IOException( "Trying to use an uninitialized "
+                                   + "event log for: " + uuid );
+        }
+        if( closed )
+        {
+            throw new IOException( "Attempt to access closed log file for : "
+                                   + uuid );
+        }
+    }
+
+    // Inherit documentation from supertype
+    public void add( RemoteEvent event ) throws IOException
+    {
+        stateCheck();
+        long id = eventCounter++;
+        RemoteEventHolder data = new RemoteEventHolder( id, event );
+        entries.add( data );
+        printControlData( persistenceLogger, "TransientEventLog::add" );
+    }
+
+    // Inherit documentation from supertype
+    public RemoteEvent next() throws IOException
+    {
+        stateCheck();
+        // Check if empty
+        if( isEmpty() )
+        {
+            throw new NoSuchElementException();
+        }
+
+        printControlData( persistenceLogger, "TransientEventLog::next" );
+        RemoteEventHolder data = (RemoteEventHolder) entries.get( 0 );
+        return (RemoteEvent) data.getRemoteEvent();
+    }
+
+    // Inherit documentation from supertype
+    public RemoteEventData[] readAhead( int maxEvents ) throws IOException
+    {
+        stateCheck();
+
+        if( maxEvents < 0 )
+        {
+            throw new IllegalArgumentException();
+        }
+
+        if( maxEvents == 0 )
+        {
+            return new RemoteEventData[0];
+        }
+
+        // Check if empty
+        if( isEmpty() )
+        {
+            throw new NoSuchElementException();
+        }
+
+        printControlData( persistenceLogger, "TransientEventLog::readAhead" );
+        int limit = ( maxEvents < entries.size() ) ? maxEvents : entries.size();
+        RemoteEventHolder[] evts = (RemoteEventHolder[])
+            entries.subList( 0, limit ).toArray( new RemoteEventHolder[0] );
+        RemoteEventData[] set = new RemoteEventData[evts.length];
+        for( int i = 0; i < set.length; i++ )
+        {
+            set[ i ] = new RemoteEventData(
+                evts[ i ].getRemoteEvent(), new Long( evts[ i ].getID() ) );
+        }
+        return set;
+    }
+
+    // Inherit documentation from supertype
+    public boolean isEmpty() throws IOException
+    {
+        stateCheck();
+        return entries.isEmpty();
+    }
+
+    // Inherit documentation from supertype
+    public void remove() throws IOException
+    {
+        stateCheck();
+        try
+        {
+            entries.remove( 0 );
+        }
+        catch( IndexOutOfBoundsException iob )
+        {
+            throw new NoSuchElementException();
+        }
+        printControlData( persistenceLogger, "TransientEventLog::remove" );
+    }
+
+    // Inherit documentation from supertype
+    public void moveAhead( Object cookie ) throws IOException
+    {
+        stateCheck();
+
+        if( cookie == null )
+        {
+            return;
+        }
+
+        if( persistenceLogger.isLoggable( Level.FINEST ) )
+        {
+            persistenceLogger.log( Level.FINEST,
+                                   "moveAhead past {0}",
+                                   cookie );
+        }
+        // TODO - trap ClassCastException and throw?
+        long lastID = ( (Long) cookie ).longValue();
+
+        if( lastID >= eventCounter )
+        {
+            throw new NoSuchElementException();
+        }
+
+        RemoteEventHolder rh = null;
+        ListIterator iter = entries.listIterator();
+        while( iter.hasNext() )
+        {
+            rh = (RemoteEventHolder) iter.next();
+            if( rh.getID() <= lastID )
+            {
+                iter.remove();
+                if( persistenceLogger.isLoggable( Level.FINEST ) )
+                {
+                    persistenceLogger.log( Level.FINEST,
+                                           "Removing event with ID {0}",
+                                           new Long( rh.getID() ) );
+                }
+            }
+            else
+            {
+                break;
+            }
+
+        }
+        printControlData( persistenceLogger, "TransientEventLog::moveAhead" );
+    }
+
+    // Inherit documentation from supertype
+    public void close() throws IOException
+    {
+        stateCheck();
+        closed = true;
+        if( persistenceLogger.isLoggable( Level.FINEST ) )
+        {
+            persistenceLogger.log( Level.FINEST,
+                                   "TransientEventLog::close for {0}", uuid );
+        }
+        // Do nothing
+    }
+
+    // Inherit documentation from supertype
+    public void delete() throws IOException
+    {
+        if( !closed )
+        {
+            throw new IOException( "Cannot delete log until it is closed" );
+        }
+        entries.clear();
+        if( persistenceLogger.isLoggable( Level.FINEST ) )
+        {
+            persistenceLogger.log( Level.FINEST,
+                                   "TransientEventLog::destroy for {0}", uuid );
+        }
+    }
+
+
+    /**
+     * Output state information to the given <tt>Logger</tt>.
+     * This is intended for debugging purposes only.
+     */
+    private void printControlData( Logger logger, String msg )
+    {
+        if( logger.isLoggable( Level.FINEST ) )
+        {
+            logger.log( Level.FINEST, "{0}", msg );
+            logger.log( Level.FINEST, "ID: {0}", uuid );
+            logger.log( Level.FINEST, "NumEvents: {0}",
+                        new Long( entries.size() ) );
+        }
+    }
+}

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientMercuryImpl.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientMercuryImpl.java?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientMercuryImpl.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/TransientMercuryImpl.java Tue Dec  9 21:16:33 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.mercury;
+
+import com.sun.jini.start.LifeCycle;
+
+/**
+ * Convenience class intended for use with the
+ * {@link com.sun.jini.start.ServiceStarter} framework to start
+ * a <i>transient</i> (non-activatable, non-persistent) implementation
+ * of Mercury.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+class TransientMercuryImpl extends MailboxImpl
+{
+
+    /**
+     * Constructs a new instance of <code>MercuryImpl</code> that is not
+     * activatable, and which will not persist its state.
+     *
+     * @param configArgs <code>String</code> array whose elements are
+     *                   the arguments to use when creating the server.
+     * @param lifeCycle  instance of <code>LifeCycle</code> that, if
+     *                   non-<code>null</code>, will cause this object's
+     *                   <code>unregister</code> method to be invoked during
+     *                   shutdown to notify the service starter framework that
+     *                   the reference to this service's implementation can be
+     *                   'released' for garbage collection. A value of
+     *                   <code>null</code> for this argument is allowed.
+     * @throws Exception If there was a problem initializing the service.
+     */
+    TransientMercuryImpl( String[] configArgs, LifeCycle lifeCycle )
+        throws Exception
+    {
+        super( configArgs, lifeCycle, false );//false ==> not persistent
+    }//end constructor
+
+}//end class TransientMercuryImpl
+

Added: incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/build.xml
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/build.xml?rev=724986&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/build.xml (added)
+++ incubator/river/jtsk/skunk/niclas1/services/mercury/src/main/java/com/sun/jini/mercury/build.xml Tue Dec  9 21:16:33 2008
@@ -0,0 +1,258 @@
+<!--
+ ! 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="mercury" 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="mercury.jar,
+		   mercury-dl.jar">
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: mercury.jar						-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="mercury.jar"
+          depends="tools">
+
+    <property name="mercury.deps" location="${build.deps}/mercury.deps"/>
+
+    <!-- ##								-->
+    <!-- ## Run ClassDep.						-->
+    <!-- ##								-->
+
+    <java classname="com.sun.jini.tool.ClassDep"
+          failonerror="true"
+          output="${mercury.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.mercury"/>
+
+      <arg value="com.sun.jini.mercury.ActivatableMercuryImpl"/>
+      <arg value="com.sun.jini.mercury.NonActivatableMercuryImpl"/>
+      <arg value="com.sun.jini.mercury.TransientMercuryImpl"/>
+      <arg value="com.sun.jini.mercury.MercuryPermission"/>
+      <arg value="com.sun.jini.mercury.MailboxImpl_Stub"/>
+
+    </java>
+
+    <!-- ##								-->
+    <!-- ## Generate the jar file.					-->
+    <!-- ##								-->
+
+    <delete file="${build.lib}/mercury.jar" quiet="true"/>
+
+    <jar destfile="${build.lib}/mercury.jar"
+         index="false"
+         manifest="${src.jini.manifest}/mercury.mf">
+
+      <fileset dir="${build.classes}" includesfile="${mercury.deps}"/>
+
+    </jar>
+
+    <!-- ##								-->
+    <!-- ## Generate the Preferred List					-->
+    <!-- ##								-->
+
+    <preferredlistgen>
+
+      <plg-elements>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib}/mercury.jar"/>
+
+        <arg line="-cp"/>
+        <arg path="${build.classes}"/>
+
+        <arg line="-default true"/>
+
+      </plg-elements>
+
+    </preferredlistgen>
+
+  </target>
+
+
+  <!-- ################################################################ -->
+  <!-- ##								-->
+  <!-- ## TARGET: mercury-dl.jar					-->
+  <!-- ##								-->
+  <!-- ################################################################ -->
+
+  <target name="mercury-dl.jar"
+          depends="tools">
+
+    <property name="mercury-dl.deps" location="${build.deps}/mercury-dl.deps"/>
+
+    <!-- ##								-->
+    <!-- ## Run ClassDep.						-->
+    <!-- ##								-->
+
+    <java classname="com.sun.jini.tool.ClassDep"
+          failonerror="true"
+          output="${mercury-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.mercury"/>
+
+      <arg value="com.sun.jini.lookup.entry.BasicServiceType"/>
+      <arg value="com.sun.jini.mercury.InternalMailboxException"/>
+      <arg value="com.sun.jini.mercury.ListenerProxy"/>
+      <arg value="com.sun.jini.mercury.MailboxAdminProxy"/>
+      <arg value="com.sun.jini.mercury.MailboxImpl_Stub"/>
+      <arg value="com.sun.jini.mercury.MailboxProxy"/>
+      <arg value="com.sun.jini.mercury.MercuryPermission"/>
+      <arg value="com.sun.jini.mercury.RemoteEventDataCursor"/>
+      <arg value="com.sun.jini.mercury.ProxyVerifier"/>
+      <arg value="com.sun.jini.mercury.Registration"/>
+      <arg value="com.sun.jini.reliableLog.LogException"/>
+      <arg value="net.jini.lookup.entry.Name"/>
+      <arg value="net.jini.lookup.entry.ServiceInfo"/>
+
+    </java>
+
+    <!-- ##								-->
+    <!-- ## Generate the jar file.					-->
+    <!-- ##								-->
+
+    <delete file="${build.lib-dl}/mercury-dl.jar" quiet="true"/>
+
+    <jar destfile="${build.lib-dl}/mercury-dl.jar"
+         index="false">
+
+      <fileset dir="${build.classes}" includesfile="${mercury-dl.deps}"/>
+
+    </jar>
+
+    <!-- ##								-->
+    <!-- ## Generate the Preferred List					-->
+    <!-- ##								-->
+
+    <preferredlistgen>
+
+      <plg-elements>
+
+        <arg line="-cp"/>
+        <arg path="${build.lib}/jsk-platform.jar"/>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib-dl}/mercury-dl.jar"/>
+
+        <arg line="-jar"/>
+        <arg path="${build.lib-dl}/jsk-dl.jar"/>
+
+        <arg line="-proxy com.sun.jini.mercury.ListenerProxy"/>
+        <arg line="-proxy com.sun.jini.mercury.MailboxAdminProxy"/>
+        <arg line="-proxy com.sun.jini.mercury.MailboxProxy"/>
+
+      </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/mercury/MailboxImpl.class"/>
+
+    </rmic>
+
+  </target>
+
+</project>
+