com.sun.jini.mercury
Class TransientEventLog

java.lang.Object
  extended by com.sun.jini.mercury.TransientEventLog
All Implemented Interfaces:
EventLog

 class TransientEventLog
extends Object
implements EventLog

Class that implements the interface for an EventLog. This class encapsulates the details of reading/writing events from/to some non-persistent mechanism. This class makes certain assumptions. First, the next and remove methods are intended to be called in pairs. If remove is not called, then subsequent calls to next will attempt to return the same object. Calling remove 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.

Since:
2.0
Author:
Sun Microsystems, Inc.

Nested Class Summary
private static class TransientEventLog.RemoteEventHolder
          Helper class used to hold a remote event and a sequence id.
 
Field Summary
private  boolean closed
          Flag that is used to determine whether or not this object has been closed.
private  List entries
          The associated, non-persistent storage for events
private  long eventCounter
          Counter used to produce event ids.
private  boolean initialized
          Flag that is used to determine whether or not this object has been initialized.
private static Logger persistenceLogger
          Logger used for persistence-related debugging messages
private  Uuid uuid
          The associated Uuid for this EventLog.
 
Constructor Summary
TransientEventLog(Uuid uuid)
          Simple constructor that takes a Uuid argument.
 
Method Summary
 void add(RemoteEvent event)
          Writes the given RemoteEvent to the underlying storage mechanism, if possible.
 void close()
          Close this log and release any associated runtime resources.
 void delete()
          Delete associated storage resources for this log.
 void init()
          Initializes the state of this EventLog object.
 boolean isEmpty()
          Returns true if this log contains no events and false otherwise.
 void moveAhead(Object cookie)
          Effectively removes the last set of read events from the log.
 RemoteEvent next()
          Return the next RemoteEvent to be read.
private  void printControlData(Logger logger, String msg)
          Output state information to the given Logger.
 RemoteEventData[] readAhead(int maxEvents)
          Return an array of RemoteEventData with a limit of maxEvents elements.
 void remove()
          Effectively removes the last read event from the log.
private  void stateCheck()
          Asserts that the log is in a valid state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

persistenceLogger

private static final Logger persistenceLogger
Logger used for persistence-related debugging messages


uuid

private Uuid uuid
The associated Uuid for this EventLog.


entries

private List entries
The associated, non-persistent storage for events


closed

private boolean closed
Flag that is used to determine whether or not this object has been closed.


initialized

private boolean initialized
Flag that is used to determine whether or not this object has been initialized.


eventCounter

private long eventCounter
Counter used to produce event ids.

Constructor Detail

TransientEventLog

TransientEventLog(Uuid uuid)
Simple constructor that takes a Uuid argument.

Throws:
IllegalArgumentException - if the argument is null
Method Detail

init

public void init()
          throws IOException
Description copied from interface: EventLog
Initializes the state of this EventLog object. The required functionality can potentially throw an IOException and has therefore been separated from from object construction.

Specified by:
init in interface EventLog
Throws:
IOException - if an I/O error occurs

stateCheck

private void stateCheck()
                 throws IOException
Asserts that the log is in a valid state.

Throws:
IOException - if the log is in an invalid state

add

public void add(RemoteEvent event)
         throws IOException
Description copied from interface: EventLog
Writes the given RemoteEvent to the underlying storage mechanism, if possible. If an IOException occurs, then the write cannot be guaranteed.

Specified by:
add in interface EventLog
Throws:
IOException - if an I/O error occurs

next

public RemoteEvent next()
                 throws IOException
Description copied from interface: EventLog
Return the next RemoteEvent to be read. Note that next is meant to be used in conjunction with remove. Subsequent calls to next will return the same event until remove is called, which actually updates the read pointer to the next event (indicating that the previously read event was successfully processed).

Specified by:
next in interface EventLog
Throws:
IOException - if an I/O error occurs

readAhead

public RemoteEventData[] readAhead(int maxEvents)
                            throws IOException
Description copied from interface: EventLog
Return an array of RemoteEventData with a limit of maxEvents elements. Note that readAhead is meant to be used in conjunction with moveAhead. Subsequent calls to readAhead with the same argument value will return the same set of events until moveAhead is called, which actually updates the read pointer to the next unread event (indicating that the previously read events were successfully processed).

Specified by:
readAhead in interface EventLog
Parameters:
maxEvents - maximum number of events/elements to return
Throws:
IOException - if an I/O error occurs

isEmpty

public boolean isEmpty()
                throws IOException
Description copied from interface: EventLog
Returns true if this log contains no events and false otherwise.

Specified by:
isEmpty in interface EventLog
Throws:
IOException

remove

public void remove()
            throws IOException
Description copied from interface: EventLog
Effectively removes the last read event from the log. It does this by advancing the read pointer to the next available event, if any.

Specified by:
remove in interface EventLog
Throws:
IOException

moveAhead

public void moveAhead(Object cookie)
               throws IOException
Description copied from interface: EventLog
Effectively removes the last set of read events from the log. It does this by advancing the read pointer to the next available event after the event associated with the provided cookie object.

Specified by:
moveAhead in interface EventLog
Parameters:
cookie - object associated with event to read past. This object should have been obtained from a call to getCookie() on a RemoteEventData object obtained from a call to readAhead on this event log.
Throws:
IOException - if there was a problem advancing the read pointer.

close

public void close()
           throws IOException
Description copied from interface: EventLog
Close this log and release any associated runtime resources.

Specified by:
close in interface EventLog
Throws:
IOException

delete

public void delete()
            throws IOException
Description copied from interface: EventLog
Delete associated storage resources for this log.

Specified by:
delete in interface EventLog
Throws:
IOException - if an IO error occurs

printControlData

private void printControlData(Logger logger,
                              String msg)
Output state information to the given Logger. This is intended for debugging purposes only.



Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.