doing house cleaning

buko [2002-11-07 00:10:31]
doing house cleaning
Filename
server/cebs/BlockingEventQueue.java
server/cebs/CebsEventSystem.java
server/cebs/Event.java
server/cebs/EventDispatcherThread.java
server/cebs/EventHandler.java
diff --git a/server/cebs/BlockingEventQueue.java b/server/cebs/BlockingEventQueue.java
deleted file mode 100644
index 91980c5..0000000
--- a/server/cebs/BlockingEventQueue.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package psl.chime4.server.cebs;
-
-import java.util.LinkedList;
-
-/**
- * BlockingEventQueue provides a simple mechanism for passing events between
- * threads. Producer threads can asynchronously place events on the queue,
- * while consumer threads can synchronously remove events from the queue. If
- * the queue is empty when a consumer thread attempts to remove an event from
- * the queue the consume thread will block until another event is placed on
- * the queue.
- *
- * @author Azubuko Obele
- * @version 0.1
- **/
-public class BlockingEventQueue
-{
-    /** list of events to stored on the queue **/
-    private LinkedList list = new LinkedList();
-
-    /** true if the queue is closed **/
-    private boolean closed = false;
-
-    /**
-     * Place an event on the queue.
-     *
-     * @param event Event object to place on the queue
-     * @throws IllegalArgumentException
-     *         if <code>event</code> is <code>null</code>
-     * @throws IllegalStateException
-     *         if the queue has been closed
-     **/
-    public synchronized final void put(Event event)
-    {
-        // add it to the list
-        list.addLast( event );
-
-        // wake up any blocking threads
-        notify();
-    }
-
-    /**
-     * Remove an Event from the queue. If the queue is empty then the calling
-     * thread blocks until another Event is added to the queue.
-     *
-     * @return Event object from the queue
-     * @throws IllegalStateException
-     *         if the queue has been closed
-     **/
-    public synchronized final Event get()
-    {
-        try
-        {
-            while ( list.size() <= 0 )
-            {
-                // while the list is empty, wait
-                wait();
-
-                // if woken up to find the queue is empty, throw the exception
-                if ( closed )
-                {
-                    String msg = "queue has been closed";
-                    throw new IllegalStateException(msg);
-                }
-            }
-
-            return (Event) list.removeFirst();
-        }
-        catch ( Exception ex )
-        {
-            // should never happen
-            String msg = "internal error in server.cebs.BlockingEventQueue";
-            throw new Error(msg);
-        }
-    }
-
-    /**
-     * Close the queue so that it continue no longer be used. Any consumer
-     * threads blocking in the get method will be woken up and an
-     * IllegalStateException will be thrown.
-     *
-     * Once this method is called any further attempts to use the queue will
-     * result in an IllegalStateException.
-     **/
-    public final void close()
-    {
-        closed = true;
-
-        // wake up all threads
-        notifyAll();
-
-        // empty the list
-        list = null;
-    }
-
-    /**
-     * Delete all Event objects on the queue.
-     **/
-    public synchronized final void clear()
-    {
-        list.clear();
-    }
-}
\ No newline at end of file
diff --git a/server/cebs/CebsEventSystem.java b/server/cebs/CebsEventSystem.java
deleted file mode 100644
index d579aad..0000000
--- a/server/cebs/CebsEventSystem.java
+++ /dev/null
@@ -1,420 +0,0 @@
-package psl.chime4.server.cebs;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * This class defines a generic interface to an underlying publish/subscribe
- * event system.
- *
- * @author Azubuko Obele
- * @version 0.1
- **/
-public abstract class CebsEventSystem
-{
-   /** counter map for storing the connection-count for each connection **/
-   private CounterMap connectionCounter = new CounterMap();
-
-   /** map for the event handlers **/
-   private Map handlerMap = new HashMap();
-
-   /** queue for incoming events **/
-   private BlockingEventQueue eventQueue = new BlockingEventQueue();
-
-   /** true iff the event system has been started **/
-   private boolean systemStarted = false;
-
-   /** EventDispatcherThread required for dispatching incoming events **/
-   private EventDispatcherThread eventDispatcherThread;
-
-   /**
-    * Construct the default event system.
-    **/
-   protected CebsEventSystem()
-   {
-      eventDispatcherThread = new EventDispatcherThread(eventQueue, this);
-   }
-
-   /**
-    * Startup the event system. No methods should be called before this
-    * method--if they are an <code>IllegalStateException</code> may be
-    * thrown.
-    **/
-   public void startup()
-   {
-      // start the event dispatcher thread
-      eventDispatcherThread.startup();
-   }
-
-   /**
-    * Shutdown the event system.
-    **/
-   public void shutdown()
-   {
-      // shutdown the event dispatcher thread
-      eventDispatcherThread.shutdown();
-   }
-
-   /**
-    * Open a connection to an event server. Before you can recieve or send
-    * events to an event server, you must first open a connection to that
-    * event server.
-    *
-    * @param host the host of the event server
-    * @param port the port of the event server
-    * @throws IllegalArgumentException
-    *         if <code>host</code> is <code>null</code>
-    * @throws IllegalStateException
-    *         if the event system has not been started
-    * @throws CebsException
-    *         if the connection could not be opened
-    **/
-   public void openConnection(String host, int port) throws CebsException
-   {
-      // check for null
-      if (host == null)
-      {
-         String msg = "host cannot be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make sure the system was started correctly
-      if (!systemStarted)
-      {
-         String msg = "must start event system before opening connections";
-         throw new IllegalStateException(msg);
-      }
-
-      // create the key for the connection
-      String key = host + ":" + port;
-
-      // get the connection count for this connection
-      int connectionCount = connectionCounter.getCount(key);
-
-      // if there are no connections to this server yet, open a real one
-      if (connectionCount == 0)
-      {
-         openRealConnection(host, port);
-      }
-
-      // increment the connection count
-      connectionCounter.incrementCount(key);
-   }
-
-   /**
-    * Open a physical connection to an event server. Subclasses should
-    * override this method to specify their protocol and what not.
-    *
-    * @param host host of the event server process to connect to
-    * @param port port of the event server process to connect to
-    * @throws CebsException
-    *         if the connection cannot be made
-    * @throws IllegalStateException
-    *         if a connection to the server already exists
-    **/
-   protected abstract void openRealConnection(String host, int port)
-      throws CebsException;
-
-   /**
-    * Close a connection to a server. This method should be called after the
-    * client is finished sending or recieving events from a server because
-    * it may free considerable system resources.
-    *
-    * @param host the host to close the connection to
-    * @param port the port of the event server process
-    * @throws IllegalArgumentException
-    *         if <code>host</code> is <code>null</code>
-    * @throws IllegalStateException
-    *         if no connection to the server exists or the system has not
-    *         been started
-    **/
-   public void closeConnection(String host, int port)
-   {
-      // check for null
-      if (host == null)
-      {
-         String msg = "host cannot be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make sure the system was started
-      if (!systemStarted)
-      {
-         String msg = "must start event system first";
-         throw new IllegalStateException(msg);
-      }
-
-      // make sure a connection exists
-      String key = host + ":" + port;
-      if (connectionCounter.getCount(key) <= 0)
-      {
-         String msg = "no connection to server exists";
-         throw new IllegalStateException(msg);
-      }
-
-      // decrement the connection count
-      connectionCounter.decrementCount(key);
-
-      // get the connection count and close if it's zero
-      if (connectionCounter.getCount(key) == 0)
-      {
-         closeRealConnection(host, port);
-      }
-   }
-
-   /**
-    * Close a physical connection to a server.
-    *
-    * @param host the host of the event server process
-    * @param port the port of the event server process
-    **/
-   protected abstract void closeRealConnection(String host, int port);
-
-   /**
-    * Publish an event to a specific server. Before calling this method the
-    * client must call the {@link openConnection} method.
-    *
-    * @param host  the host to publish the event to
-    * @param port  the port of the event server process
-    * @param topic the topic to publish the event on
-    * @param event the event to actually publish
-    * @throws IllegalArgumentException
-    *         if any parameter is <code>null</code>
-    * @throws IllegalStateException
-    *         if no connection to the server exists or if the event system
-    *         has not been started
-    * @throws CebsException
-    *         if the event cannot be published
-    **/
-   public void publish(String host, int port, String topic, Event event)
-      throws CebsException
-   {
-      // check for null
-      if ((host == null) || (topic == null) || (event == null))
-      {
-         String msg = "no param can be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make sure the system's been started
-      if (!systemStarted)
-      {
-         String msg = "must start event system first";
-         throw new IllegalStateException(msg);
-      }
-
-      // make sure the connection exists
-      String key = host + ":" + port;
-      if (connectionCounter.getCount(key) <= 0)
-      {
-         String msg = "must open connection before sending events";
-         throw new IllegalStateException(msg);
-      }
-
-      // add routing information to the event
-      event.put("xxx.event.topic", topic);
-      event.put("xxx.event.source.server.host", host);
-      event.put("xxx.event.source.server.port", port);
-
-      sendEvent(host, port, topic, event);
-   }
-
-   /**
-    * Actually send an event to a server on a specific topic. This method
-    * cannot be before the {@link openConnection} method.
-    *
-    * @param host  the host to publish the event to
-    * @param port  port of the event server process
-    * @param topic topic to publish the event under
-    * @param event event to actually send
-    * @throws CebsException
-    *         if the event cannot be sent
-    **/
-   protected abstract void sendEvent(String host, int port, String topic,
-                                     Event event) throws CebsException;
-
-
-   /**
-    * Register an event handler to recieve events published under a given
-    * topic from a given server.
-    *
-    * @param host    host that is managing the topic
-    * @param port    port of the event server process
-    * @param topic   the topic to subscribe to
-    * @param handler handler to handle events published on <code>topic</code>
-    * @throws IllegalArgumentException
-    *         if any parameter is <code>null</code>
-    * @throws IllegalStateException
-    *         if no connection was made to server or if the server has not
-    *         been started
-    * @throws CebsException
-    *         if the subscription could not be made
-    **/
-   public void registerEventHandler(String host, int port, String topic,
-                                    EventHandler handler)
-      throws CebsException
-   {
-      // check for null
-      if ((host == null) || (topic == null) || (handler == null))
-      {
-         String msg = "no parameter can be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make sure the system's been started
-      if (!systemStarted)
-      {
-         String msg = "must first start server";
-         throw new IllegalStateException(msg);
-      }
-
-      // make sure a connection has been opened
-      String connkey = host + ":" + port;
-      if (connectionCounter.getCount(connkey) <= 0)
-      {
-         String msg = "must open connection before sending events";
-         throw new IllegalStateException(msg);
-      }
-
-      // make the key
-      String key = host + ":" + port + ":" + topic;
-      handlerMap.put(key, handler);
-
-      // tell the underlying connection to really make the subscription
-      addSubscription(host, port, topic);
-   }
-
-   /**
-    * Subscribe to a specific topic on a specific event server.
-    *
-    * @param host  the event server
-    * @param port  port of the event server
-    * @param topic topic to subscribe too
-    * @throws CebsException
-    *         if the subscription cannot be made
-    **/
-   protected abstract void addSubscription(String host, int port,
-                                           String topic)
-      throws CebsException;
-
-   /**
-    * Unregister an event handler that no longer wants to subscribe to a
-    * given topic.
-    *
-    * @param host  the event server subscribed to
-    * @param port  the port of the event server process
-    * @param topic the topic to unsubscribe from
-    * @throws IllegalArgumentException
-    *         if any parameter is <code>null</code>
-    * @throws IllegalStateException
-    *         if no connection to the server exists or if the event system
-    *         has not been started
-    * @throws CebsException
-    *         if the subscription to the event server cannot be undone
-    **/
-   public void unregisterEventHandler(String host, int port, String topic)
-      throws CebsException
-   {
-      // check for null
-      if ((host == null) || (topic == null))
-      {
-         String msg = "no param may be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make sure that the event system was started
-      if (!systemStarted)
-      {
-         String msg = "must start event system first";
-         throw new IllegalStateException(msg);
-      }
-
-      // make sure a connection has been opened
-      String connkey = host + ":" + port;
-      if (connectionCounter.getCount(connkey) <= 0)
-      {
-         String msg = "must open connection before sending events";
-         throw new IllegalStateException(msg);
-      }
-
-      // remove it from the map
-      String key = host + ":" + port + ":" + topic;
-      handlerMap.remove(key);
-
-      // remove the subscription
-      removeSubscription(host, port, topic);
-   }
-
-   /**
-    * Remove a subscription from an event server.
-    *
-    * @param host  the host of the event server
-    * @param port  the port of the event server process
-    * @param topic the topic to unsubscribe from
-    * @throws CebsException
-    *         if the subscription cannot be removed
-    **/
-   protected abstract void removeSubscription(String host, int port,
-                                              String topic)
-      throws CebsException;
-
-   /**
-    * Get an EventHandler subscribed to a topic on a given host.
-    *
-    * @param host  the host of the event server
-    * @param port  port of the event server process
-    * @param topic the topic the event was published under
-    * @throws IllegalArgumentException
-    *         if <code>host</code> or <code>topic</code> is <code>null</code>
-    * @return EventHandler subscribed to <code>topic</code> or
-    *         <code>null</code>
-    **/
-   EventHandler getEventHandler(String host, int port, String topic)
-   {
-      // check for null
-      if ((host == null) || (topic == null))
-      {
-         String msg = "no parameter may be null";
-         throw new IllegalArgumentException(msg);
-      }
-
-      // make the key
-      String key = host + ":" + port + ":" + topic;
-      return (EventHandler) handlerMap.get(key);
-   }
-
-   /**
-    * When an event is actually recieved by the underlying event system
-    * subclasses should call this method in order to place the event within
-    * the event system.
-    *
-    * @param event the event that was recieved
-    **/
-   protected void eventRecieved(Event event)
-   {
-      if (event != null)
-      {
-         eventQueue.put(event);
-      }
-   }
-
-   /**
-    * Create an empty event. No guarantee is made on the uniqueness of the
-    * returned event object. For performance reasons, the underlying event
-    * system implementation may wish to pool Event objects therefore clients
-    * may be unknowingly reusing the same event.
-    *
-    * @return an empty Event object
-    **/
-   public abstract Event createEmptyEvent();
-}
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/server/cebs/Event.java b/server/cebs/Event.java
deleted file mode 100644
index f3cb061..0000000
--- a/server/cebs/Event.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package psl.chime4.server.cebs;
-
-import java.io.Serializable;
-
-/**
- * An event represents a significant change in the state of some object
- * within the Chime system or a request by one object to another object.
- *
- * @author Azubuko Obele
- * @version 0.1
- **/
-public abstract class Event implements Serializable
-{
-   /**
-    * Determine whether an event contains a value mapped to a given key.
-    *
-    * @param key the key to test for existence
-    * @return <code>true</code> if the event contains a value mapped to
-    *         <code>key</code>, else <code>false</code>
-    **/
-   public abstract boolean containsKey(String key);
-
-   /**
-    * Erase all key/value pairs within the event.
-    **/
-   public abstract void clear();
-
-   /**
-    * Get an integer value stored in the event.
-    *
-    * @param key the index the integer is stored under in the event
-    * @return integer value mapped to <code>key</code>
-    * @throws IllegalArgumentException
-    *         if event does not contain <code>key</code>
-    **/
-   public abstract int getInteger(String key);
-
-   /**
-    * Get a long value stored in the event.
-    *
-    * @param key the index the long is stored under in the event
-    * @return long value mapped to <code>key</code>
-    * @throws IllegalArgumentException
-    *         if event does not contain <code>key</code>
-    **/
-   public abstract long getLong(String key);
-
-   /**
-    * Get a double value stored in the event.
-    *
-    * @param key the index the double is stored under in the event
-    * @return double value mapped to <code>key</code>
-    * @throws IllegalArgumentException
-    *         if event does not contain <code>key</code>
-    **/
-   public abstract double getDouble(String key);
-
-   /**
-    * Get an ASCII string stored in the event.
-    *
-    * @param key the index the string is stored under in the event
-    * @return string value mapped to <code>key</code>
-    * @throws IllegalArgumentException
-    *         if event does not contain <code>key</code>
-    **/
-   public abstract String getString(String key);
-
-   /**
-    * Get an array of arbitrary bytes stored in the event.
-    *
-    * @param key the index the byte array is stored under in the event
-    * @return byte[] value mapped to <code>key</code>
-    * @throws IllegalArgumentException
-    *         if event does not contain <code>key</code>
-    **/
-   public abstract byte[] getByteArray(String key);
-
-   /**
-    * Put an integer value into the event.
-    *
-    * @param key the key to store the integer value under
-    * @param val the value of the integer value
-    **/
-   public abstract void put(String key, int val);
-
-   /**
-    * Put a long value into the event.
-    *
-    * @param key the key to store the long value under
-    * @param val the value of the integer value
-    **/
-   public abstract void put(String key, long val);
-
-   /**
-    * Put a double value into the event.
-    *
-    * @param key the key to store the double value under
-    * @param val the double to store into the event
-    **/
-   public abstract void put(String key, double val);
-
-   /**
-    * Put an ASCII string value into the event.
-    *
-    * @param key the key to store the String value under
-    * @param val the value of the String value
-    * @throws IllegalArgumentException
-    *         if <code>val</code> is <code>null</code>
-    **/
-   public abstract void put(String key, String val);
-
-   /**
-    * Put an array of bytes into the event.
-    *
-    * @param key the key to store the byte array under
-    * @param val the bytes to store into the event
-    **/
-   public abstract void put(String key, byte[] val);
-
-   /**
-    * Remove a value from the event.
-    *
-    * @param key the value is mapped to in the event
-    **/
-   public abstract  void remove(String key);
-}
\ No newline at end of file
diff --git a/server/cebs/EventDispatcherThread.java b/server/cebs/EventDispatcherThread.java
deleted file mode 100644
index a4bedf6..0000000
--- a/server/cebs/EventDispatcherThread.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package psl.chime4.server.cebs;
-
-/**
- * The EventDispatcherThread removes incoming Events from the queue and
- * passes them on to registered EventHandlers.
- *
- * @author Azubuko Obele
- * @version 0.1
- **/
-class EventDispatcherThread extends Thread
-{
-    /** true if the thread is running **/
-    private boolean running = false;
-
-    /** the blocking queue to remove events from **/
-    private BlockingEventQueue incomingEvents;
-
-    /** the event system the thread gets EventHandlers from **/
-    private CebsEventSystem eventSystem;
-
-    /**
-     * Construct a new EventDispatcherThread.
-     *
-     * @param blockingQueue the queue to remove incoming events from
-     * @param eventSystem   the system that contains event handlers
-     * @throws IllegalArgumentException
-     *         if <code>blockingQueue</code> or <code>eventSystem</code>
-     *         is <code>null</code>
-     **/
-    EventDispatcherThread(BlockingEventQueue blockingQueue,
-                          CebsEventSystem eventSystem)
-    {
-        // check for null
-        if ( (blockingQueue == null) || (eventSystem == null) )
-        {
-            String msg = "no parameter can be null";
-            throw new IllegalArgumentException(msg);
-        }
-
-        this.incomingEvents = blockingQueue;
-        this.eventSystem = eventSystem;
-    }
-
-    /**
-     * Start the EventDispatcherThread. It will now begin removing events
-     * from the events queue and passing them on to to Event Handlers.
-     **/
-    public void startup()
-    {
-        running = true;
-        super.start();
-    }
-
-    /**
-     * Shutdown the EventDispatcherThread so it will stop running.
-     **/
-    public void shutdown()
-    {
-        running = false;
-    }
-
-    /**
-     * The main thread method. Continously try to remove events from the
-     * blocking queue and pass them to the correct event handler.
-     **/
-    public void run()
-    {
-        while (running)
-        {
-            try
-            {
-                // remove the next event
-                Event event = incomingEvents.get();
-
-                // get the event routing information
-                String topic = event.getString("xxx.event.topic");
-                String host = event.getString("xxx.event.source.server.host");
-                int port = event.getInteger("xxx.event.source.server.port");
-
-                // make sure that routing information was added to the event
-                if ((topic == null) || (host == null) || (port < 0))
-                {
-                   String msg = "event contained no routing information";
-                   throw new IllegalStateException(msg);
-                }
-
-                // get the correct event handler
-                EventHandler handler =
-                    eventSystem.getEventHandler(host, port, topic);
-
-                // if there is one, ask the handler to handle it
-                if (handler != null)
-                {
-                    handler.handleEvent( event );
-                }
-            }
-            catch (Exception e)
-            {
-                // stop the thread from running
-                shutdown();
-            }
-        }
-    }
-}
\ No newline at end of file
diff --git a/server/cebs/EventHandler.java b/server/cebs/EventHandler.java
deleted file mode 100644
index 38849d2..0000000
--- a/server/cebs/EventHandler.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package psl.chime4.server.cebs;
-
-/**
- * An EventHandler object encapsulates the logic required to handle a certain
- * class of events.
- *
- * @author Azubuko Obele
- * @version 0.1
- **/
-public interface EventHandler extends java.io.Serializable
-{
-    /**
-     * Handle a given Event by executing the event logic needed to process
-     * it.
-     *
-     * Note that the Event Dispatcher thread executes this method and it is
-     * very important that this method execute in a reasonable amount of time
-     * so that the Event Dispatcher can continue passing events to other
-     * event handlers. If an EventHandler needs more than a reasonable amount
-     * of time to handle an event it must start its own thread in order to
-     * handle that event.
-     *
-     * @param event the event to be handled
-     **/
-    public void handleEvent(Event event);
-}
\ No newline at end of file