geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578421 [1/3] - in /geronimo/sandbox/gshell/trunk/gshell-remote: gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/ gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/ gshell-remote-common/s...
Date Sat, 22 Sep 2007 12:42:28 GMT
Author: jdillon
Date: Sat Sep 22 05:42:24 2007
New Revision: 578421

URL: http://svn.apache.org/viewvc?rev=578421&view=rev
Log:
Moving bits around a little to try and separate the framework stuff from the rsh client/server stuff
Renamed MarshallingUtil to Marshaller and added instance methods to simplify usage where complex marshall/unmarshall is performed
Created transport/base/* which has the base classes which handle the transport bits (instead of leaving them in the tcp impl)
Adding our own thread model impl so we can control that better.  Now each transport and transport server gets its own executor... and now the vm:// transports work again... yay!
Um and well... lots of other stuff :-|

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/
      - copied from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java   (contents, props changed)
      - copied, changed from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java   (contents, props changed)
      - copied, changed from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/EchoMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/ExecuteMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/HandShakeMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/LoginMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/OpenShellMessage.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/package-info.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestEncoder.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/
      - copied from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/ExecutorThreadModel.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ConnectException.java   (contents, props changed)
      - copied, changed from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ConnectionException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportExceptionMonitor.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseCommon.java   (contents, props changed)
      - copied, changed from r578377, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportCommon.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java   (contents, props changed)
      - copied, changed from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportFactory.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransportServer.java   (contents, props changed)
      - copied, changed from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/package-info.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/NamedThreadFactory.java   (with props)
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Externalizable.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshallingUtil.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MessageCodecFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CloseShellMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/EchoMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/ExecuteMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/HandShakeMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/LoginMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/OpenShellMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ConnectionException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportCommon.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/SessionAttributeBinder.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/package-info.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/package-info.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/security/SecurityFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/SessionAttributeBinder.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/session/package-info.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionInputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/SessionOutputStream.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/stream/WriteStreamMessage.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportFactoryLocator.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ssl/SslTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/tcp/TcpTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportFactory.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/vm/VmTransportServer.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/DefaultRemoteShell.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-server/src/main/java/org/apache/geronimo/gshell/remote/server/RshServerMessageVisitor.java

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClient.java Sat Sep 22 05:42:24 2007
@@ -25,13 +25,13 @@
 import java.security.PublicKey;
 
 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
-import org.apache.geronimo.gshell.remote.message.CloseShellMessage;
-import org.apache.geronimo.gshell.remote.message.EchoMessage;
-import org.apache.geronimo.gshell.remote.message.ExecuteMessage;
-import org.apache.geronimo.gshell.remote.message.HandShakeMessage;
-import org.apache.geronimo.gshell.remote.message.LoginMessage;
 import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.OpenShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
 import org.apache.geronimo.gshell.remote.transport.Transport;
 import org.apache.geronimo.gshell.remote.transport.TransportFactory;
 import org.slf4j.Logger;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-client/src/main/java/org/apache/geronimo/gshell/remote/client/RshClientMessageVisitor.java Sat Sep 22 05:42:24 2007
@@ -19,9 +19,9 @@
 
 package org.apache.geronimo.gshell.remote.client;
 
-import org.apache.geronimo.gshell.remote.message.EchoMessage;
 import org.apache.geronimo.gshell.remote.message.MessageVisitor;
 import org.apache.geronimo.gshell.remote.message.MessageVisitorSupport;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
 import org.codehaus.plexus.component.annotations.Component;
 
 /**

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.marshall;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MarshalAware
+{
+    void writeExternal(final ByteBuffer out) throws Exception;
+
+    void readExternal(final ByteBuffer in) throws Exception;
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/MarshalAware.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,370 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.marshall;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.util.UUID;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * Provides support for marshalling and unmarshalling objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Marshaller
+{
+    //
+    // TODO: Should we maybe look at using XStream to handle cases when things don't marshall normally?
+    //
+    
+    private final ByteBuffer buff;
+
+    public Marshaller(final ByteBuffer buff) {
+        assert buff != null;
+
+        this.buff = buff;
+    }
+
+    public static MarshalAware unmarshal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        Class type = (Class) readObject(in);
+
+        MarshalAware obj = (MarshalAware) type.newInstance();
+
+        obj.readExternal(in);
+
+        return obj;
+    }
+
+    public MarshalAware unmarshal() throws Exception {
+        return unmarshal(buff);
+    }
+
+    public static void marshal(final ByteBuffer out, final MarshalAware obj) throws Exception {
+        assert out != null;
+
+        writeObject(out, obj.getClass());
+
+        obj.writeExternal(out);
+    }
+
+    public void marshal(final MarshalAware obj) throws Exception {
+        marshal(buff, obj);
+    }
+
+    //
+    // Boolean Serialization
+    //
+
+    private static final byte TRUE = 1;
+
+    private static final byte FALSE = 0;
+
+    public static boolean readBoolean(final ByteBuffer in) {
+        assert in != null;
+
+        byte b = in.get();
+
+        if (b == TRUE) {
+            return true;
+        }
+        else if (b == FALSE) {
+            return false;
+        }
+        else {
+            throw new Error();
+        }
+    }
+
+    public boolean getBoolean() {
+        return readBoolean(buff);
+    }
+
+    public static void writeBoolean(final ByteBuffer out, final boolean bool) {
+        assert out != null;
+
+        if (bool) {
+            out.put(TRUE);
+        }
+        else {
+            out.put(FALSE);
+        }
+    }
+
+    public void put(final boolean bool) {
+        writeBoolean(buff, bool);
+    }
+
+    //
+    // Byte[] Serialization
+    //
+
+    public static byte[] readBytes(final ByteBuffer in) {
+        assert in != null;
+
+        boolean isNull = readBoolean(in);
+
+        if (isNull) {
+            return null;
+        }
+
+        int len = in.getInt();
+
+        byte[] bytes = new byte[len];
+
+        in.get(bytes);
+
+        return bytes;
+    }
+
+    public byte[] getBytes() {
+        return readBytes(buff);
+    }
+
+    public static void writeBytes(final ByteBuffer out, final byte[] bytes) {
+        assert out != null;
+
+        if (bytes == null) {
+            writeBoolean(out, true);
+        }
+        else {
+            writeBoolean(out, false);
+
+            out.putInt(bytes.length);
+
+            out.put(bytes);
+        }
+    }
+
+    public void put(final byte[] bytes) {
+        writeBytes(buff, bytes);
+    }
+
+    //
+    // ByteBuffer Serialization
+    //
+
+    public static ByteBuffer readBuffer(final ByteBuffer in) {
+        assert in != null;
+
+        byte[] bytes = readBytes(in);
+
+        if (bytes == null) {
+            return null;
+        }
+
+        return ByteBuffer.wrap(bytes);
+    }
+
+    public ByteBuffer getBuffer() {
+        return readBuffer(buff);
+    }
+
+    public static void writeBuffer(final ByteBuffer out, final ByteBuffer buffer) {
+        assert out != null;
+
+        if (buffer == null) {
+            writeBytes(out, null);
+        }
+        else {
+            writeBoolean(out, false);
+
+            out.putInt(buffer.remaining());
+
+            out.put(buffer);
+        }
+    }
+
+    public void put(final ByteBuffer b) {
+        writeBuffer(buff, b);
+    }
+
+    //
+    // Object Serialization
+    //
+
+    public static Object readObject(final ByteBuffer in) throws IOException, ClassNotFoundException {
+        assert in != null;
+
+        byte[] bytes = readBytes(in);
+
+        if (bytes == null) {
+            return null;
+        }
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+        ObjectInputStream ois = new ObjectInputStream(bais);
+
+        return ois.readObject();
+    }
+
+    public Object getObject() throws IOException, ClassNotFoundException {
+        return readObject(buff);
+    }
+
+    public static void writeObject(final ByteBuffer out, final Object obj) throws IOException {
+        assert out != null;
+
+        byte[] bytes = null;
+
+        if (obj != null) {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+            oos.writeObject(obj);
+            oos.flush();
+
+            bytes = baos.toByteArray();
+        }
+
+        writeBytes(out, bytes);
+    }
+
+    public void put(final Object obj) throws IOException {
+        writeObject(buff, obj);
+    }
+
+    //
+    // String Serialization
+    //
+
+    private static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
+
+    public static String readString(final ByteBuffer in) throws CharacterCodingException {
+        assert in != null;
+
+        int len = in.getInt();
+
+        if (len == -1) {
+            return null;
+        }
+
+        return in.getString(len, UTF_8_CHARSET.newDecoder());
+    }
+
+    public String getString() throws CharacterCodingException {
+        return readString(buff);
+    }
+
+    public static void writeString(final ByteBuffer out, final String str) throws CharacterCodingException {
+        assert out != null;
+
+        if (str == null) {
+            out.putInt(-1);
+        }
+        else {
+            int len = str.length();
+            out.putInt(len);
+
+            out.putString(str, len, UTF_8_CHARSET.newEncoder());
+        }
+    }
+
+    public void put(final String str) throws CharacterCodingException {
+        writeString(buff, str);
+    }
+
+    //
+    // UUID Serialization
+    //
+
+    public static UUID readUuid(final ByteBuffer in) {
+        assert in != null;
+
+        boolean isNull = readBoolean(in);
+
+        if (isNull) {
+            return null;
+        }
+
+        long msb = in.getLong();
+
+        long lsb = in.getLong();
+
+        return new UUID(msb, lsb);
+    }
+
+    public UUID getUuid() {
+        return readUuid(buff);
+    }
+
+    public static void writeUuid(final ByteBuffer out, final UUID uuid) {
+        assert out != null;
+
+        if (uuid == null) {
+            writeBoolean(out, true);
+        }
+        else {
+            writeBoolean(out, false);
+
+            out.putLong(uuid.getMostSignificantBits());
+
+            out.putLong(uuid.getLeastSignificantBits());
+        }
+    }
+
+    public void put(final UUID uuid) {
+        writeUuid(buff, uuid);
+    }
+
+    //
+    // Enum Serialization (adapted from Mina 2.x)
+    //
+
+    public static ByteBuffer writeEnum(final ByteBuffer out, Enum<?> e) {
+        if (e.ordinal() > Byte.MAX_VALUE) {
+            throw new IllegalArgumentException(enumConversionErrorMessage(e, "byte"));
+        }
+
+        return out.put((byte) e.ordinal());
+    }
+
+    public void put(Enum<?> e) {
+        writeEnum(buff, e);
+    }
+
+    public static <E extends Enum<E>> E readEnum(final ByteBuffer in, final Class<E> enumClass) {
+        return toEnum(enumClass, in.get());
+    }
+
+    public <E extends Enum<E>> E getEnum(final Class<E> enumClass) {
+        return readEnum(buff, enumClass);
+    }
+
+    private static <E> E toEnum(Class<E> enumClass, int i) {
+        E[] enumConstants = enumClass.getEnumConstants();
+        if (i > enumConstants.length) {
+            throw new IndexOutOfBoundsException(String.format("%d is too large of an ordinal to convert to the enum %s", i, enumClass.getName()));
+        }
+        return enumConstants[i];
+    }
+
+    private static String enumConversionErrorMessage(Enum<?> e, String type) {
+        return String.format("%s.%s has an ordinal value too large for a %s", e.getClass().getName(), e.name(), type);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/Marshaller.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/package-info.java?rev=578421&r1=578362&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/package-info.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/marshall/package-info.java Sat Sep 22 05:42:24 2007
@@ -18,8 +18,8 @@
  */
 
 /**
- * Encoding and decoding fluff.
+ * Marshalling support.
  *
  * @version $Rev$ $Date$
  */
-package org.apache.geronimo.gshell.remote.codec;
\ No newline at end of file
+package org.apache.geronimo.gshell.remote.marshall;
\ No newline at end of file

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/CryptoAwareMessageSupport.java Sat Sep 22 05:42:24 2007
@@ -21,9 +21,9 @@
 
 import java.security.Key;
 
-import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
 import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
 import org.apache.mina.common.ByteBuffer;
 
 /**
@@ -31,13 +31,13 @@
  *
  * @version $Rev$ $Date$
  */
-public abstract class CryptoAwareMessageSupport
+public class CryptoAwareMessageSupport
     extends MessageSupport
     implements CryptoContextAware
 {
     private transient CryptoContext ctx;
 
-    public CryptoAwareMessageSupport(final MessageType type) {
+    protected CryptoAwareMessageSupport(final MessageType type) {
         super(type);
     }
 
@@ -58,7 +58,7 @@
     protected String decryptString(final ByteBuffer in) throws Exception {
         assert in != null;
 
-        byte[] bytes = MarshallingUtil.readBytes(in);
+        byte[] bytes = Marshaller.readBytes(in);
         
         if (bytes == null) {
             return null;
@@ -79,7 +79,7 @@
             bytes = getCryptoContext().encrypt(key, str.getBytes());
         }
 
-        MarshallingUtil.writeBytes(out, bytes);
+        Marshaller.writeBytes(out, bytes);
     }
 
     protected void encryptString(final ByteBuffer out, final String str) throws Exception {

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message;
+
+/**
+ * Thrown to indicate an invalid message was received.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidMessageException
+    extends MessageException
+{
+    private static final long serialVersionUID = 1;
+
+    public InvalidMessageException(final Object msg) {
+        super("Invalid message: " + msg + " (" + (msg != null ? msg.getClass() : "<null>") + ")");
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/InvalidMessageException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java Sat Sep 22 05:42:24 2007
@@ -22,7 +22,7 @@
 import java.io.IOException;
 import java.io.Serializable;
 
-import org.apache.geronimo.gshell.remote.codec.Externalizable;
+import org.apache.geronimo.gshell.remote.marshall.MarshalAware;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
 
@@ -32,7 +32,7 @@
  * @version $Rev$ $Date$
  */
 public interface Message
-    extends Externalizable
+    extends MarshalAware
 {
     ID getId();
 
@@ -62,8 +62,12 @@
     // ID
     //
 
+    //
+    // HACK: Make these serializable for now... need to figure out how to do the generic encode/decode of MarshalAware instances
+    //
+    
     interface ID
-        extends Serializable
+        extends MarshalAware, Serializable
     {
         // Marker
     }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java (from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java&r1=578362&r2=578421&rev=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/codec/MessageCodecFactory.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java Sat Sep 22 05:42:24 2007
@@ -17,36 +17,15 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.codec;
-
-import java.io.ByteArrayOutputStream;
-import java.nio.channels.Channels;
-import java.nio.channels.WritableByteChannel;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+package org.apache.geronimo.gshell.remote.message;
 
 import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
-import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
-import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageType;
-import org.apache.geronimo.gshell.remote.request.Request;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolCodecException;
-import org.apache.mina.filter.codec.ProtocolDecoderOutput;
-import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.geronimo.gshell.remote.request.RequestEncoder;
 import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
-import org.apache.mina.filter.codec.demux.MessageDecoder;
-import org.apache.mina.filter.codec.demux.MessageDecoderFactory;
-import org.apache.mina.filter.codec.demux.MessageDecoderResult;
-import org.apache.mina.filter.codec.demux.MessageEncoder;
-import org.apache.mina.filter.codec.demux.MessageEncoderFactory;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 
 /**
  * Provides encoding and decoding support for {@link Message} instances.
@@ -56,267 +35,22 @@
 @Component(role=MessageCodecFactory.class)
 public class MessageCodecFactory
     extends DemuxingProtocolCodecFactory
+    implements Initializable
 {
-    private static final byte[] MAGIC = { 'g', 's', 'h', 0 };
-
-    private static final byte VERSION = 1;
-
-    private static final int HEADER_SIZE =
-            MAGIC.length +
-            1 + // version (byte)
-            1 + // message type (enum byte)
-            4;  // body length (int)
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
     @Requirement
     private CryptoContext crypto;
 
-    public MessageCodecFactory() {
-        register(new EncoderFactory());
-        
-        register(new DecoderFactory());
-
-        register(new RequestEncoderFactory());
-    }
-
-    private void attachCryptoContext(final Message msg) {
-        // We need to do a little bit of extra fluff to hook up support for encrypted messages
-        if (msg instanceof CryptoContextAware) {
-            log.trace("Attaching crypto context to: {}", msg);
-
-            ((CryptoContextAware)msg).setCryptoContext(crypto);
-        }
-    }
-
-    private void writeMagic(final ByteBuffer out) throws Exception {
-        assert out != null;
-
-        out.put(MAGIC);
-    }
-
-    private byte[] readMagic(final ByteBuffer in) throws Exception {
-        assert in != null;
-
-        byte[] bytes = new byte[MAGIC.length];
-
-        in.get(bytes);
-
-        if (!Arrays.equals(MAGIC, bytes)) {
-            throw new ProtocolCodecException("Invalid MAGIC");
-        }
-
-        return bytes;
-    }
-
-    private void writeVersion(final ByteBuffer out) throws Exception {
-        assert out != null;
-
-        out.put(VERSION);
-    }
-
-    private byte readVersion(final ByteBuffer in) throws Exception {
-        assert in != null;
-
-        byte version = in.get();
-
-        if (VERSION != version) {
-            throw new ProtocolCodecException("Invalid version");
-        }
-
-        return version;
-    }
-
-    private byte[] marshal(final Message msg) throws Exception {
-        assert msg != null;
-
-        log.trace("Marshalling: {}", msg);
-        
-        ByteBuffer out = ByteBuffer.allocate(256, false);
-        out.setAutoExpand(true);
-
-        writeMagic(out);
-
-        writeVersion(out);
-
-        MarshallingUtil.writeEnum(out, msg.getType());
-
-        // Determine the length of the message body
-        out.mark();
-        out.putInt(0);
-        msg.writeExternal(out);
-
-        int bodyStart = HEADER_SIZE;
-        int pos = out.position();
-        int len = pos - bodyStart;
-
-        out.reset();
-        
-        // Write the length of the body
-        out.putInt(len);
-        out.position(pos);
-        out.limit(pos);
-        out.flip();
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
-        WritableByteChannel channel = Channels.newChannel(baos);
-        channel.write(out.buf());
-        channel.close();
-
-        byte[] bytes = baos.toByteArray();
-
-        log.trace("Marshalled size: {} bytes", bytes.length);
-
-        return bytes;
-    }
-
-    //
-    // Encoder
-    //
-
-    public class EncoderFactory
-        implements MessageEncoderFactory
-    {
-        public MessageEncoder getEncoder() throws Exception {
-            return new Encoder();
-        }
-    }
-
-    public class Encoder
-        implements MessageEncoder
-    {
-        public Set<Class<?>> getMessageTypes() {
-            return MessageType.types();
-        }
-
-        public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
-            assert session != null;
-            assert message != null;
-            assert out != null;
-
-            Message msg = (Message)message;
-
-            log.trace("Encoding: {}", msg);
-
-            attachCryptoContext(msg);
-
-            byte[] bytes = marshal(msg);
-
-            log.trace("Encoded {} bytes", bytes.length);
-
-            out.write(ByteBuffer.wrap(bytes));
-        }
-    }
-
-    //
-    // Decoder
-    //
-
-    public class DecoderFactory
-        implements MessageDecoderFactory
-    {
-        public MessageDecoder getDecoder() throws Exception {
-            return new Decoder();
-        }
-    }
-
-    public class Decoder
-        implements MessageDecoder
-    {
-        public MessageDecoderResult decodable(final IoSession session, final ByteBuffer in) {
-            assert session != null;
-            assert in != null;
-
-            if (in.remaining() < HEADER_SIZE) {
-                return MessageDecoderResult.NEED_DATA;
-            }
-
-            try {
-                readMagic(in);
-
-                readVersion(in);
-
-                MessageType type = MarshallingUtil.readEnum(in, MessageType.class);
-
-                if (type == null) {
-                    return MessageDecoderResult.NOT_OK;
-                }
-            }
-            catch (Exception e) {
-                return MessageDecoderResult.NOT_OK;
-            }
-
-            // Make sure we have all of the data we need
-            int len = in.getInt();
-            
-            if (in.remaining() != len) {
-                return MessageDecoderResult.NEED_DATA;
-            }
-
-            return MessageDecoderResult.OK;
-        }
-
-        public MessageDecoderResult decode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception {
-            assert session != null;
-            assert in != null;
-            assert out != null;
-
-            readMagic(in);
-
-            readVersion(in);
-
-            MessageType type = MarshallingUtil.readEnum(in, MessageType.class);
-
-            Message msg = MessageType.create(type);
-
-            attachCryptoContext(msg);
-
-            int len = in.getInt();
-
-            log.trace("Decoding {} bytes", len);
-
-            msg.readExternal(in);
-
-            log.trace("Decoded: {}", msg);
-
-            out.write(msg);
-
-            return MessageDecoderResult.OK;
-        }
-
-        public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {}
-    }
-
-    //
-    // RequestEncoder
-    //
-
-    public class RequestEncoderFactory
-        implements MessageEncoderFactory
-    {
-        public MessageEncoder getEncoder() throws Exception {
-            return new RequestEncoder();
-        }
-    }
-
-    public class RequestEncoder
-        extends Encoder
-    {
-        public Set<Class<?>> getMessageTypes() {
-            Set<Class<?>> types = new HashSet<Class<?>>();
-
-            types.add(Request.class);
+    public MessageCodecFactory() {}
 
-            return Collections.unmodifiableSet(types);
-        }
+    public void initialize() throws InitializationException {
+        register(new MessageEncoder.Factory(crypto));
 
-        public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
-            Request request = (Request) message;
+        register(new MessageDecoder.Factory(crypto));
 
-            Message msg = request.getMessage();
+        //
+        // TODO: For now hook up the reqeust encoding here, would like to find a better way though...
+        //
 
-            super.encode(session, msg, out);
-        }
+        register(new RequestEncoder.Factory(crypto));
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,162 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+import java.util.Arrays;
+
+import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.filter.codec.ProtocolCodecException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Support for {@link Message} encoders and decoders.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageCodecSupport
+{
+    protected static final byte[] MAGIC = { 'g', 's', 'h', 0 };
+
+    protected static final byte VERSION = 1;
+
+    /**
+     * The size of the message header, which is made up of:
+     *
+     * <ol>
+     * <li>MAGIC (4 bytes)</li>
+     * <li>VERSION (1 byte)</li>
+     * <li>MESSAGE TYPE (1 byte: enum)</li>
+     * <li>BODY LENGTH (4 bytes: int)</li>
+     * </ol>
+     */
+    protected static final int HEADER_SIZE = MAGIC.length + 1 + 1 + 4;
+
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+
+    protected final CryptoContext crypto;
+
+    protected MessageCodecSupport(final CryptoContext crypto) {
+        assert crypto != null;
+
+        this.crypto = crypto;
+    }
+
+    protected void writeMagic(final ByteBuffer out) throws Exception {
+        assert out != null;
+
+        out.put(MAGIC);
+    }
+
+    protected byte[] readMagic(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        byte[] bytes = new byte[MAGIC.length];
+
+        in.get(bytes);
+
+        if (!Arrays.equals(MAGIC, bytes)) {
+            throw new ProtocolCodecException("Invalid MAGIC");
+        }
+
+        return bytes;
+    }
+
+    protected void writeVersion(final ByteBuffer out) throws Exception {
+        assert out != null;
+
+        out.put(VERSION);
+    }
+
+    protected byte readVersion(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        byte version = in.get();
+
+        if (VERSION != version) {
+            throw new ProtocolCodecException("Invalid version");
+        }
+
+        return version;
+    }
+
+    protected byte[] marshal(final Message msg) throws Exception {
+        assert msg != null;
+
+        log.trace("Marshalling: {}", msg);
+
+        ByteBuffer out = ByteBuffer.allocate(256, false);
+        out.setAutoExpand(true);
+
+        writeMagic(out);
+
+        writeVersion(out);
+
+        Marshaller.writeEnum(out, msg.getType());
+
+        // Determine the length of the message body
+        out.mark();
+        out.putInt(0);
+        msg.writeExternal(out);
+
+        int bodyStart = HEADER_SIZE;
+        int pos = out.position();
+        int len = pos - bodyStart;
+
+        out.reset();
+
+        // Write the length of the body
+        out.putInt(len);
+        out.position(pos);
+        out.limit(pos);
+        out.flip();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        WritableByteChannel channel = Channels.newChannel(baos);
+        channel.write(out.buf());
+        channel.close();
+
+        byte[] bytes = baos.toByteArray();
+
+        log.trace("Marshalled size: {} bytes", bytes.length);
+
+        return bytes;
+    }
+
+    /**
+     * Support for {@link Message} encoder and decoder factories.
+     */
+    protected static class FactorySupport
+    {
+        protected final CryptoContext crypto;
+
+        protected FactorySupport(final CryptoContext crypto) {
+            assert crypto != null;
+
+            this.crypto = crypto;
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageCodecSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,124 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message;
+
+import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
+import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.demux.MessageDecoderFactory;
+import org.apache.mina.filter.codec.demux.MessageDecoderResult;
+
+/**
+ * Decodes {@link Message} instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageDecoder
+    extends MessageCodecSupport
+    implements org.apache.mina.filter.codec.demux.MessageDecoder
+{
+    public MessageDecoder(final CryptoContext crypto) {
+        super(crypto);
+    }
+
+    public MessageDecoderResult decodable(final IoSession session, final ByteBuffer in) {
+        assert session != null;
+        assert in != null;
+
+        if (in.remaining() < HEADER_SIZE) {
+            return MessageDecoderResult.NEED_DATA;
+        }
+
+        try {
+            readMagic(in);
+
+            readVersion(in);
+
+            MessageType type = Marshaller.readEnum(in, MessageType.class);
+
+            if (type == null) {
+                return MessageDecoderResult.NOT_OK;
+            }
+        }
+        catch (Exception e) {
+            return MessageDecoderResult.NOT_OK;
+        }
+
+        // Make sure we have all of the data we need
+        int len = in.getInt();
+
+        if (in.remaining() != len) {
+            return MessageDecoderResult.NEED_DATA;
+        }
+
+        return MessageDecoderResult.OK;
+    }
+
+    public MessageDecoderResult decode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception {
+        assert session != null;
+        assert in != null;
+        assert out != null;
+
+        readMagic(in);
+
+        readVersion(in);
+
+        MessageType type = Marshaller.readEnum(in, MessageType.class);
+
+        Message msg = MessageType.create(type);
+
+        if (msg instanceof CryptoContextAware) {
+            ((CryptoContextAware)msg).setCryptoContext(crypto);
+        }
+
+        int len = in.getInt();
+
+        log.trace("Decoding {} bytes", len);
+
+        msg.readExternal(in);
+
+        log.trace("Decoded: {}", msg);
+
+        out.write(msg);
+
+        return MessageDecoderResult.OK;
+    }
+
+    public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {}
+
+    /**
+     * Produces {@link MessageDecoder} instances.
+     */
+    public static class Factory
+        extends FactorySupport
+        implements MessageDecoderFactory
+    {
+        public Factory(final CryptoContext crypto) {
+            super(crypto);
+        }
+
+        public org.apache.mina.filter.codec.demux.MessageDecoder getDecoder() throws Exception {
+            return new MessageDecoder(crypto);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageDecoder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message;
+
+import java.util.Set;
+
+import org.apache.geronimo.gshell.remote.crypto.CryptoContext;
+import org.apache.geronimo.gshell.remote.crypto.CryptoContextAware;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.demux.MessageEncoderFactory;
+
+/**
+ * Encodes {@link Message} instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageEncoder
+    extends MessageCodecSupport
+    implements org.apache.mina.filter.codec.demux.MessageEncoder
+{
+    public MessageEncoder(final CryptoContext crypto) {
+        super(crypto);
+    }
+
+    public Set<Class<?>> getMessageTypes() {
+        return MessageType.types();
+    }
+
+    public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
+        assert session != null;
+        assert message != null;
+        assert out != null;
+
+        Message msg = (Message)message;
+
+        log.trace("Encoding: {}", msg);
+
+        if (msg instanceof CryptoContextAware) {
+            ((CryptoContextAware)msg).setCryptoContext(crypto);
+        }
+
+        byte[] bytes = marshal(msg);
+
+        log.trace("Encoded {} bytes", bytes.length);
+
+        out.write(ByteBuffer.wrap(bytes));
+    }
+
+    /**
+     * Produces {@link MessageEncoder} instances.
+     */
+    public static class Factory
+        extends FactorySupport
+        implements MessageEncoderFactory
+    {
+        public Factory(final CryptoContext crypto) {
+            super(crypto);
+        }
+
+        public org.apache.mina.filter.codec.demux.MessageEncoder getEncoder() throws Exception {
+            return new MessageEncoder(crypto);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageEncoder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,47 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message;
+
+/**
+ * Thrown to indicate a message operation failed.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageException
+    extends RuntimeException
+{
+    private static final long serialVersionUID = 1;
+
+    public MessageException(final String msg, final Throwable cause) {
+        super(msg, cause);
+    }
+
+    public MessageException(final String msg) {
+        super(msg);
+    }
+
+    public MessageException(final Throwable cause) {
+        super(cause);
+    }
+
+    public MessageException() {
+        super();
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java (from r578362, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java&r1=578362&r2=578421&rev=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/ProtocolHandler.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java Sat Sep 22 05:42:24 2007
@@ -17,95 +17,88 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.transport;
+package org.apache.geronimo.gshell.remote.message;
 
-import org.apache.geronimo.gshell.remote.message.Message;
-import org.apache.geronimo.gshell.remote.message.MessageVisitor;
-import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
 import org.codehaus.plexus.component.annotations.Component;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Provides the basic protocol handling for clients and servers.
+ * Provides handling for {@link Message} messages.
  *
  * @version $Rev$ $Date$
  */
-@Component(role=ProtocolHandler.class)
-public class ProtocolHandler
-    implements IoHandler
+@Component(role=MessageHandler.class)
+public class MessageHandler
+    extends IoHandlerAdapter
 {
-    private final Logger log = LoggerFactory.getLogger(getClass());
+    //
+    // TODO: Shall we make this a filter?
+    //
     
-    private MessageVisitor visitor;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public MessageHandler(final MessageVisitor visitor) {
+        assert visitor != null;
 
-    public MessageVisitor getVisitor() {
-        return visitor;
+        this.visitor = visitor;
     }
+    
+    private MessageVisitor visitor;
 
     public void setVisitor(final MessageVisitor visitor) {
+        assert visitor != null;
+        
         this.visitor = visitor;
     }
 
-    //
-    // TODO: Do we need to stuff the visitor into the session context?
-    //
+    @Override
+    public void sessionCreated(final IoSession session) throws Exception {
+        // log.debug("Session created: {}", session);
 
-    public void sessionCreated(IoSession session) throws Exception {
-        log.debug("Session created: {}", session);
+        MessageVisitor.BINDER.bind(session, visitor);
     }
 
+    @Override
     public void sessionOpened(final IoSession session) throws Exception {
-        log.debug("Session opened: {}", session);
-    }
-
-    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
-        log.debug("Session idle: {}, status: {}", session, status);
+        // log.debug("Session opened: {}", session);
     }
 
+    @Override
     public void sessionClosed(final IoSession session) throws Exception {
-        log.debug("Session closed: {}", session);
+        // log.debug("Session closed: {}", session);
+
+        MessageVisitor.BINDER.unbind(session);
     }
 
+    @Override
     public void messageReceived(final IoSession session, final Object obj) throws Exception {
-        log.debug("Message received: {}, message: {}", session, obj);
+        // log.debug("Message received: {}, message: {}", session, obj);
         
-        //
-        // TODO: Need to handle Exception muck, and send faul messages back to clients
-        //
-
         if (obj instanceof Message) {
-            // This is the main protocol action, set the session, freeze the message and
-            // then process the message with our visitor
-
-            final Message msg = (Message)obj;
+            Message msg = (Message)obj;
 
+            // Attach the session to the context
             msg.setSession(session);
             msg.freeze();
 
-            //
-            // TODO: Make sure we have a visitor... gotta have it really...
-            //
-            
-            if (visitor != null) {
-                msg.process(visitor);
-            }
-            else {
-                log.warn("Unable to process message because vistor has not been bound; ignoring");
-            }
+            // Hand over to visitor for processing
+            MessageVisitor v = MessageVisitor.BINDER.lookup(session);
+            msg.process(v);
         }
         else {
-            log.error("Unhandled message: {}", obj);
+            throw new InvalidMessageException(obj);
         }
     }
 
-    public void messageSent(IoSession session, Object message) throws Exception {
-        log.debug("Message sent: {}, message: {}", session, message);
-    }
-
+    @Override
     public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception {
-        log.error("Exception caught: " + session + ", cause: " + cause, cause);
+        //
+        // TODO: Need to handle Exception muck, and send faul messages back to clients ?
+        //
+
+        log.error("Unhandled exception: " + cause, cause);
     }
 }

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java Sat Sep 22 05:42:24 2007
@@ -25,7 +25,7 @@
 
 import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
-import org.apache.geronimo.gshell.remote.codec.MarshallingUtil;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -35,7 +35,7 @@
  *
  * @version $Rev$ $Date$
  */
-public abstract class MessageSupport
+public class MessageSupport
     implements Message
 {
     private static final IDGenerator ID_GENERATOR = new LongIDGenerator();
@@ -144,17 +144,13 @@
 
         return session.write(msg);
     }
-    
-    //
-    // Externalization
-    //
 
     public void readExternal(final ByteBuffer in) throws Exception {
         assert in != null;
 
-        id = (ID) MarshallingUtil.readObject(in);
+        id = (ID) Marshaller.readObject(in);
 
-        correlationId = (ID) MarshallingUtil.readObject(in);
+        correlationId = (ID) Marshaller.readObject(in);
 
         timestamp = in.getLong();
 
@@ -164,9 +160,9 @@
     public void writeExternal(final ByteBuffer out) throws Exception {
         assert out != null;
 
-        MarshallingUtil.writeObject(out, id);
+        Marshaller.writeObject(out, id);
 
-        MarshallingUtil.writeObject(out, correlationId);
+        Marshaller.writeObject(out, correlationId);
 
         out.putLong(timestamp);
 
@@ -196,7 +192,7 @@
     private static class LongID
         implements ID
     {
-        private final Long value;
+        private Long value;
 
         public LongID(final long value) {
             this.value = value;
@@ -223,6 +219,15 @@
         public String toString() {
             return String.valueOf(value);
         }
+
+        public void writeExternal(final ByteBuffer out) throws Exception {
+            out.putLong(value);
+
+        }
+
+        public void readExternal(final ByteBuffer in) throws Exception {
+            value = in.getLong();
+        }
     }
 
     //
@@ -233,7 +238,7 @@
         implements IDGenerator
     {
         public ID generate() {
-            return new UUIDAdapter(UUID.randomUUID());
+            return new UUIDAdapter();
         }
     }
 
@@ -244,12 +249,16 @@
     private static class UUIDAdapter
         implements ID
     {
-        private final UUID value;
+        private UUID value;
 
         public UUIDAdapter(final UUID value) {
             this.value = value;
         }
 
+        public UUIDAdapter() {
+            this(UUID.randomUUID());
+        }
+
         public int hashCode() {
             return value.hashCode();
         }
@@ -270,6 +279,15 @@
 
         public String toString() {
             return String.valueOf(value);
+        }
+
+        public void writeExternal(final ByteBuffer out) throws Exception {
+            Marshaller.writeUuid(out, value);
+
+        }
+
+        public void readExternal(final ByteBuffer in) throws Exception {
+            value = Marshaller.readUuid(in);
         }
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageType.java Sat Sep 22 05:42:24 2007
@@ -23,6 +23,12 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.HandShakeMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.LoginMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
 import org.apache.geronimo.gshell.remote.stream.WriteStreamMessage;
 
 /**
@@ -32,6 +38,10 @@
  */
 public enum MessageType
 {
+    //
+    // FIXME: Abstract me...
+    //
+    
     ECHO                    (EchoMessage.class),
     HANDSHAKE               (HandShakeMessage.class),
     HANDSHAKE_RESULT        (HandShakeMessage.Result.class),

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitor.java Sat Sep 22 05:42:24 2007
@@ -19,6 +19,12 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
+import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
+
 /**
  * Provides an abstraction layer for message processing.
  *
@@ -26,6 +32,12 @@
  */
 public interface MessageVisitor
 {
+    //
+    // FIXME: Abstract me...
+    //
+    
+    SessionAttributeBinder<MessageVisitor> BINDER = new SessionAttributeBinder<MessageVisitor>(MessageVisitor.class);
+
     void visitEcho(EchoMessage msg) throws Exception;
 
     void visitOpenShell(OpenShellMessage msg) throws Exception;

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageVisitorSupport.java Sat Sep 22 05:42:24 2007
@@ -19,6 +19,10 @@
 
 package org.apache.geronimo.gshell.remote.message;
 
+import org.apache.geronimo.gshell.remote.message.rsh.CloseShellMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.EchoMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.ExecuteMessage;
+import org.apache.geronimo.gshell.remote.message.rsh.OpenShellMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,15 +31,17 @@
  *
  * @version $Rev$ $Date$
  */
-public abstract class MessageVisitorSupport
+public class MessageVisitorSupport
     implements MessageVisitor
 {
-    protected final Logger log = LoggerFactory.getLogger(getClass());
-
     //
-    // MessageVisitor
+    // FIXME: Abstract me...
     //
+    
+    protected final Logger log = LoggerFactory.getLogger(getClass());
 
+    protected MessageVisitorSupport() {}
+    
     public void visitEcho(EchoMessage msg) throws Exception {}
 
     public void visitOpenShell(OpenShellMessage msg) throws Exception {}

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/package-info.java?rev=578421&r1=578420&r2=578421&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/package-info.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/package-info.java Sat Sep 22 05:42:24 2007
@@ -18,7 +18,7 @@
  */
 
 /**
- * Message protocol support for client to server communictation.
+ * Support for message protocols.
  *
  * @version $Rev$ $Date$
  */

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java?rev=578421&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java Sat Sep 22 05:42:24 2007
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.geronimo.gshell.remote.message.rsh;
+
+import org.apache.geronimo.gshell.remote.message.MessageSupport;
+import org.apache.geronimo.gshell.remote.message.MessageType;
+import org.apache.geronimo.gshell.remote.message.MessageVisitor;
+
+/**
+ * Close the remote shell instance.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CloseShellMessage
+    extends MessageSupport
+{
+    public CloseShellMessage() {
+        super(MessageType.CLOSE_SHELL);
+    }
+
+    public void process(final MessageVisitor visitor) throws Exception {
+        assert visitor != null;
+
+        visitor.visitCloseShell(this);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/rsh/CloseShellMessage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message