directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 9671 - incubator/directory/eve/trunk/eve/frontend/encoder/pojo-impl/src/java/org/apache/eve/encoder/impl
Date Mon, 22 Mar 2004 10:32:20 GMT
Author: akarasulu
Date: Mon Mar 22 02:32:20 2004
New Revision: 9671

Modified:
   incubator/directory/eve/trunk/eve/frontend/encoder/pojo-impl/src/java/org/apache/eve/encoder/impl/DefaultEncoderManager.java
Log:
added encoder implementation

Modified: incubator/directory/eve/trunk/eve/frontend/encoder/pojo-impl/src/java/org/apache/eve/encoder/impl/DefaultEncoderManager.java
==============================================================================
--- incubator/directory/eve/trunk/eve/frontend/encoder/pojo-impl/src/java/org/apache/eve/encoder/impl/DefaultEncoderManager.java
(original)
+++ incubator/directory/eve/trunk/eve/frontend/encoder/pojo-impl/src/java/org/apache/eve/encoder/impl/DefaultEncoderManager.java
Mon Mar 22 02:32:20 2004
@@ -17,21 +17,118 @@
 package org.apache.eve.encoder.impl ;
 
 
+import java.nio.ByteBuffer;
+import java.util.EventObject;
+
+import org.apache.commons.codec.EncoderException;
 import org.apache.eve.encoder.EncoderManager ;
+import org.apache.eve.encoder.EncoderManagerMonitor;
+import org.apache.eve.event.AbstractSubscriber;
+import org.apache.eve.event.EventRouter;
+import org.apache.eve.event.OutputEvent;
+import org.apache.eve.event.ResponseEvent;
+import org.apache.eve.event.ResponseSubscriber;
+import org.apache.eve.seda.DefaultStage;
+import org.apache.eve.seda.DefaultStageConfig;
+import org.apache.eve.seda.StageHandler;
+import org.apache.eve.seda.LoggingStageMonitor;
+import org.apache.ldap.common.message.MessageEncoder;
+import org.apache.ldap.common.message.Response;
 
 
 /**
+ * The default EncoderManager.  For now we're modeling this as a simple one
+ * shot encode module but this will change as well build stateful encoders which
+ * will fragment a response into multiple output events.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">
  * Apache Directory Project</a>
  * @version $Rev$
  */
-public class DefaultEncoderManager implements EncoderManager
+public class DefaultEncoderManager extends DefaultStage 
+    implements EncoderManager, ResponseSubscriber
 {
+    /** the event router used to publish and subscribe to events on */
+    private final EventRouter router ;
+    private EncoderManagerMonitor monitor ;
+    
+    
+    /**
+     * Creates the default EncoderManager.
+     * 
+     * @param router the event router used to publish and subscribe to events on
+     */
+    public DefaultEncoderManager( EventRouter router, 
+                                  DefaultStageConfig config )
+    {
+        super( config ) ;
+        super.setMonitor( new LoggingStageMonitor( this.getClass() ) ) ;
+        config.setHandler( new EncoderStageHandler() ) ;
+        this.router = router ;
+        this.router.subscribe( ResponseEvent.class, this ) ;
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.eve.event.Subscriber#inform(java.util.EventObject)
+     */
+    public void inform( EventObject event )
+    {
+        try
+        {
+            AbstractSubscriber.inform( this, event ) ;
+        }
+        catch( Throwable t )
+        {
+            monitor.failedOnInform( this, event, t ) ;
+        }
+    }
+    
+    
     /* (non-Javadoc)
-     * @see org.apache.eve.processor.RequestProcessor#dummy()
+     * @see org.apache.eve.event.ResponseSubscriber#inform(
+     * org.apache.eve.event.ResponseEvent)
      */
-    public void dummy()
+    public void inform( ResponseEvent event )
+    {
+        super.enqueue( event ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.eve.encoder.EncoderManager#encode(
+     * org.apache.ldap.common.message.Response)
+     */
+    public byte[] encode( Response response ) throws EncoderException
+    {
+        MessageEncoder encoder = new MessageEncoder() ;
+        return encoder.encode( response ) ;
+    }
+    
+    
+    class EncoderStageHandler implements StageHandler
     {
+        /* (non-Javadoc)
+         * @see org.apache.eve.seda.StageHandler#handleEvent(
+         * java.util.EventObject)
+         */
+        public void handleEvent( EventObject generic )
+        {
+            ByteBuffer buf = null ;
+            ResponseEvent event = ( ResponseEvent ) generic ;
+            
+            try
+            {
+                buf = ByteBuffer.wrap( encode( event.getResponse() ) ) ;
+            }
+            catch ( EncoderException e )
+            {
+                monitor.failedOnEncode( DefaultEncoderManager.this, event, e ) ;
+            }
+            
+            OutputEvent outEvent = new OutputEvent( DefaultEncoderManager.this, 
+                    event.getClientKey(), buf ) ;
+            router.publish( outEvent ) ;
+        }
     }
 }

Mime
View raw message