[jboss-cvs] JBoss Messaging SVN: r4059 - in trunk/src/main/org/jboss/messaging/core/remoting/impl: mina and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 15 09:16:52 EDT 2008
Author: timfox
Date: 2008-04-15 09:16:52 -0400 (Tue, 15 Apr 2008)
New Revision: 4059
Added:
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
Log:
Missing files
Added: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java 2008-04-15 13:16:52 UTC (rev 4059)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.codec;
+
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
+
+/**
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ */
+public class EmptyPacketCodec extends AbstractPacketCodec<PacketImpl>
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public EmptyPacketCodec(final PacketType type)
+ {
+ super(type);
+ }
+
+ // Public --------------------------------------------------------
+
+ // AbstractPacketCodec overrides ---------------------------------
+
+ protected int getBodyLength(final PacketImpl packet)
+ {
+ return 0;
+ }
+
+ @Override
+ protected void encodeBody(final PacketImpl packet, final RemotingBuffer out) throws Exception
+ {
+ }
+
+ @Override
+ protected Packet decodeBody(final RemotingBuffer in) throws Exception
+ {
+ return new PacketImpl(type);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
+
+//static class CodecForEmptyPacket<P extends Packet> extends
+//AbstractPacketCodec<P>
+//{
+//
+//public CodecForEmptyPacket(PacketType type)
+//{
+//super(type);
+//}
+//
+//@Override
+//protected void encodeBody(P packet, RemotingBuffer out) throws Exception
+//{
+//// no body
+//out.putInt(0);
+//}
+//
+//@Override
+//protected Packet decodeBody(RemotingBuffer in) throws Exception
+//{
+//in.getInt(); // skip body length
+//return new PacketImpl(type);
+//}
+//}
Added: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java 2008-04-15 13:16:52 UTC (rev 4059)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.mina;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.mina.common.IoBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.Packet;
+import org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec;
+import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
+
+/**
+ *
+ * A MessagingCodec
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class MessagingCodec extends CumulativeProtocolDecoder implements ProtocolEncoder
+{
+ private static final Logger log = Logger.getLogger(MessagingCodec.class);
+
+
+ private final Map<PacketType, AbstractPacketCodec<?>> codecs =
+ new HashMap<PacketType, AbstractPacketCodec<?>>();
+
+ // ProtocolEncoder implementation ------------------------------------------------------------
+
+ public void dispose(final IoSession session) throws Exception
+ {
+ }
+
+ public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception
+ {
+ Packet packet = (Packet)message;
+
+ AbstractPacketCodec codec = codecs.get(packet.getType());
+
+ if (codec == null)
+ {
+ throw new IllegalStateException("no encoder has been registered for " + packet);
+ }
+
+ codec.encode(packet, out);
+ }
+
+ // CumulataveProtocolDecoder overrides --------------------------------------------------------
+
+ protected boolean doDecode(final IoSession session, final IoBuffer in, final ProtocolDecoderOutput out) throws Exception
+ {
+ if (in.remaining() > AbstractPacketCodec.INT_LENGTH)
+ {
+ int length = in.getInt();
+
+ log.info("length is " + length);
+
+ if (in.remaining() < length)
+ {
+ //Need more data
+ return true;
+ }
+ }
+ else
+ {
+ //Need more data
+ return true;
+ }
+
+ byte packetType = in.get();
+
+ log.info("packet type is " + packetType);
+
+ AbstractPacketCodec codec = codecs.get(packetType);
+
+ if (codec == null)
+ {
+ throw new IllegalStateException("no encoder has been registered for " + packetType);
+ }
+
+ return codec.decode(new BufferWrapper(in), out);
+ }
+
+ // Public --------------------------------------------------------
+
+ public void put(PacketType type, AbstractPacketCodec codec)
+ {
+ codecs.put(type, codec);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list