geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578566 [2/4] - in /geronimo/sandbox/gshell/trunk/gshell-whisper: ./ src/ src/main/java/org/apache/geronimo/gshell/remote/ src/main/java/org/apache/geronimo/gshell/whisper/ src/main/java/org/apache/geronimo/gshell/whisper/crypto/ src/main/j...
Date Sun, 23 Sep 2007 12:02:52 GMT
Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,115 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.crypto.CryptoContextAware;
+import org.apache.geronimo.gshell.whisper.marshal.Marshaller;
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.MessageType;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultMessageMarshaller
+    implements MessageMarshaller
+{
+    private final MessageProvider provider;
+
+    public DefaultMessageMarshaller(final MessageProvider provider) {
+        this.provider = provider;
+    }
+
+    public String toString() {
+        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+    }
+    
+    public void marshal(final ByteBuffer out, final Message msg) throws Exception {
+        MessageHeader header = provider.getMessageHeader();
+
+        header.writeExternal(out);
+
+        Marshaller.writeObject(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();
+    }
+
+    public byte[] marshal(final Message msg) throws Exception {
+        ByteBuffer out = ByteBuffer.allocate(256, false);
+        out.setAutoExpand(true);
+
+        marshal(out, msg);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+        WritableByteChannel channel = Channels.newChannel(baos);
+        channel.write(out.buf());
+        channel.close();
+
+        return baos.toByteArray();
+    }
+
+    public Message unmarshal(final ByteBuffer in) throws Exception {
+        MessageHeader header = provider.getMessageHeader();
+
+        header.readExternal(in);
+
+        MessageType type = (MessageType) Marshaller.readObject(in);
+
+        Message msg = provider.getMessageFactory().create(type);
+
+        //
+        // FIXME: This could be handled by the factory...
+        //
+
+        if (msg instanceof CryptoContextAware) {
+            ((CryptoContextAware)msg).setCryptoContext(provider.getCryptoContext());
+        }
+
+        int len = in.getInt(); // ignored for now
+
+        msg.readExternal(in);
+
+        return msg;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageMarshaller.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,138 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.util.Set;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.crypto.CryptoContext;
+import org.apache.geronimo.gshell.whisper.request.RequestEncoder;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.demux.DemuxingProtocolCodecFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultMessageProvider
+    implements MessageProvider
+{
+    private MessageHeader header;
+
+    private Set<Class<?>> types;
+
+    private MessageFactory factory;
+
+    private MessageIDFactory idFactory;
+
+    private MessageMarshaller marshaller;
+    
+    private ProtocolCodecFactory codecFactory;
+
+    private CryptoContext cryptoContext;
+
+    public DefaultMessageProvider(final MessageHeader header, final Set<Class<?>> messageTypes) {
+        this.header = header;
+        
+        this.types = messageTypes;
+
+        this.factory = new DefaultMessageFactory();
+
+        this.idFactory = new LongMessageID.Factory();
+
+        this.marshaller = new DefaultMessageMarshaller(this);
+
+        DemuxingProtocolCodecFactory factory = new DemuxingProtocolCodecFactory();
+
+        factory.register(new MessageDecoder.Factory(this));
+
+        factory.register(new MessageEncoder.Factory(this));
+
+        //
+        // TODO: Need to find a better way to get this puppy registered na...
+        //
+
+        factory.register(new RequestEncoder.Factory(this));
+
+        this.codecFactory = factory;
+    }
+
+    public String toString() {
+        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+    }
+
+    public MessageHeader getMessageHeader() {
+        return header;
+    }
+
+    public void setMessageHeader(final MessageHeader header) {
+        this.header = header;
+    }
+
+    public Set<Class<?>> getMessageTypes() {
+        return types;
+    }
+
+    public void setMessageTypes(final Set<Class<?>> types) {
+        this.types = types;
+    }
+
+    public MessageFactory getMessageFactory() {
+        return factory;
+    }
+
+    public void setMessageFactory(final MessageFactory factory) {
+        this.factory = factory;
+    }
+
+    public MessageIDFactory getMessageIDFactory() {
+        return idFactory;
+    }
+
+    public void setMessageIDFactory(final MessageIDFactory idFactory) {
+        this.idFactory = idFactory;
+    }
+
+    public MessageMarshaller getMessageMarshaller() {
+        return marshaller;
+    }
+
+    public void setMessageMarshaller(final MessageMarshaller marshaller) {
+        this.marshaller = marshaller;
+    }
+
+    public ProtocolCodecFactory getProtocolCodecFactory() {
+        return codecFactory;
+    }
+
+    public void setProtocolCodecFactory(final ProtocolCodecFactory factory) {
+        this.codecFactory = factory;
+    }
+
+    public CryptoContext getCryptoContext() {
+        return cryptoContext;
+    }
+
+    public void setCryptoContext(final CryptoContext context) {
+        this.cryptoContext = context;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/DefaultMessageProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,86 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class LongMessageID
+    implements MessageID
+{
+    private Long value;
+
+    public LongMessageID(final long value) {
+        this.value = value;
+    }
+
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        else if (obj == null) {
+            return false;
+        }
+        else if (!(obj instanceof LongMessageID)) {
+            return false;
+        }
+
+        return value.equals(((LongMessageID)obj).value);
+    }
+
+    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();
+    }
+
+    public static class Factory
+        implements MessageIDFactory
+    {
+        private static final AtomicLong COUNTER = new AtomicLong(0);
+        
+        public MessageID create() {
+            return new LongMessageID(COUNTER.getAndIncrement());
+        }
+
+        public String toString() {
+            return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/LongMessageID.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageDecoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageDecoder.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageDecoder.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageDecoder.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,116 @@
+/*
+ * 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.whisper.message.spi;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.marshal.Marshaller;
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.MessageType;
+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.MessageDecoderResult;
+
+/**
+ * Decodes {@link Message} instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageDecoder
+    implements org.apache.mina.filter.codec.demux.MessageDecoder
+{
+    private final MessageProvider provider;
+
+    public MessageDecoder(final MessageProvider provider) {
+        this.provider = provider;
+    }
+
+    public String toString() {
+        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+    }
+    
+    public MessageDecoderResult decodable(final IoSession session, final ByteBuffer in) {
+        assert session != null;
+        assert in != null;
+
+        MessageHeader header = provider.getMessageHeader();
+
+        if (in.remaining() < header.size()) {
+            return MessageDecoderResult.NEED_DATA;
+        }
+
+        //
+        // FIXME: Use the MessageMarshaller instancer here some how..., maybe even unmarshall in a try/catch would work for now
+        //
+        
+        try {
+            header.readExternal(in);
+
+            MessageType type = (MessageType) Marshaller.readObject(in);
+
+            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;
+
+        MessageMarshaller marshaller = provider.getMessageMarshaller();
+
+        Message msg = marshaller.unmarshal(in);
+
+        out.write(msg);
+
+        return MessageDecoderResult.OK;
+    }
+
+    public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {}
+
+    public static class Factory
+        implements org.apache.mina.filter.codec.demux.MessageDecoderFactory
+    {
+        private MessageProvider provider;
+
+        public Factory(final MessageProvider provider) {
+            this.provider = provider;
+        }
+
+        public org.apache.mina.filter.codec.demux.MessageDecoder getDecoder() throws Exception {
+            return new MessageDecoder(provider);
+        }
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageEncoder.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageEncoder.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageEncoder.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,89 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.util.Set;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.crypto.CryptoContextAware;
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+/**
+ * Encodes {@link Message} instances.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageEncoder
+    implements org.apache.mina.filter.codec.demux.MessageEncoder
+{
+    private final MessageProvider provider;
+
+    public MessageEncoder(final MessageProvider provider) {
+        this.provider = provider;
+    }
+
+    public String toString() {
+        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+    }
+
+    public Set<Class<?>> getMessageTypes() {
+        return provider.getMessageTypes();
+    }
+
+    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;
+
+        //
+        // FIXME: This could be handled by the factory...
+        //
+
+        if (msg instanceof CryptoContextAware) {
+            ((CryptoContextAware)msg).setCryptoContext(provider.getCryptoContext());
+        }
+
+        MessageMarshaller marshaller = provider.getMessageMarshaller();
+
+        byte[] bytes = marshaller.marshal(msg);
+
+        out.write(ByteBuffer.wrap(bytes));
+    }
+
+    public static class Factory
+        implements org.apache.mina.filter.codec.demux.MessageEncoderFactory
+    {
+        private MessageProvider provider;
+
+        public Factory(final MessageProvider provider) {
+            this.provider = provider;
+        }
+
+        public org.apache.mina.filter.codec.demux.MessageEncoder getEncoder() throws Exception {
+            return new MessageEncoder(provider);
+        }
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,33 @@
+/*
+ * 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.whisper.message.spi;
+
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.MessageType;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageFactory
+{
+    Message create(MessageType type) throws Exception;
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java Sun Sep 23 05:02:46 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.whisper.message.spi;
+
+import org.apache.geronimo.gshell.whisper.marshal.MarshalAware;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageHeader
+    extends MarshalAware
+{
+    int size();
+    
+    byte[] magic();
+
+    byte version();
+
+    /*
+    MessageType type();
+
+    int length();
+    */
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageHeader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.whisper.message.spi;
+
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageIDFactory
+{
+    MessageID create();
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageIDFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,37 @@
+/*
+ * 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.whisper.message.spi;
+
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageMarshaller
+{
+    Message unmarshal(ByteBuffer in) throws Exception;
+
+    void marshal(ByteBuffer out, Message msg) throws Exception;
+
+    byte[] marshal(Message msg) throws Exception;
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageMarshaller.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java Sun Sep 23 05:02:46 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.whisper.message.spi;
+
+import java.util.Set;
+
+import org.apache.geronimo.gshell.whisper.crypto.CryptoContext;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MessageProvider
+{
+    MessageHeader getMessageHeader();
+
+    Set<Class<?>> getMessageTypes();
+
+    MessageFactory getMessageFactory();
+
+    MessageIDFactory getMessageIDFactory();
+
+    MessageMarshaller getMessageMarshaller();
+
+    ProtocolCodecFactory getProtocolCodecFactory();
+
+    CryptoContext getCryptoContext();
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/MessageProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,89 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.util.UUID;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.marshal.Marshaller;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class UUIDMessageID
+    implements MessageID
+{
+    private UUID value;
+
+    public UUIDMessageID(final UUID value) {
+        this.value = value;
+    }
+
+    public UUIDMessageID() {
+        this(UUID.randomUUID());
+    }
+
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        else if (obj == null) {
+            return false;
+        }
+        else if (!(obj instanceof UUIDMessageID)) {
+            return false;
+        }
+
+        return value.equals(((UUIDMessageID)obj).value);
+    }
+
+    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);
+    }
+
+    public static class Factory
+        implements MessageIDFactory
+    {
+        public MessageID create() {
+            return new UUIDMessageID();
+        }
+
+        public String toString() {
+            return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UUIDMessageID.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,89 @@
+/*
+ * 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.whisper.message.spi;
+
+import java.util.UUID;
+
+import org.apache.geronimo.gshell.common.tostring.ReflectionToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.marshal.Marshaller;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class UUIDMessageID
+    implements MessageID
+{
+    private UUID value;
+
+    public UUIDMessageID(final UUID value) {
+        this.value = value;
+    }
+
+    public UUIDMessageID() {
+        this(UUID.randomUUID());
+    }
+
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        else if (obj == null) {
+            return false;
+        }
+        else if (!(obj instanceof UUIDMessageID)) {
+            return false;
+        }
+
+        return value.equals(((UUIDMessageID)obj).value);
+    }
+
+    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);
+    }
+
+    public static class Factory
+        implements MessageIDFactory
+    {
+        public MessageID create() {
+            return new UUIDMessageID();
+        }
+
+        public String toString() {
+            return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/UuidMessageID.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+package org.apache.geronimo.gshell.whisper.message.spi;
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/message/spi/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,229 @@
+/*
+ * 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.whisper.request;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.geronimo.gshell.common.Duration;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a request message.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Request
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    final Lock lock = new ReentrantLock();
+
+    private final BlockingQueue<Object> responses = new LinkedBlockingQueue<Object>();
+
+    private final Message message;
+
+    private final Duration timeout;
+
+    private volatile boolean endOfResponses;
+
+    private volatile boolean signaled;
+
+    public Request(final Message message, final Duration timeout) {
+        assert message != null;
+        assert timeout != null;
+
+        this.message = message;
+        this.timeout = timeout;
+    }
+
+    public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
+        this(message, new Duration(timeout, timeoutUnit));
+    }
+
+    public int hashCode() {
+        return getId().hashCode();
+    }
+
+    public boolean equals(final Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        else if (obj == null) {
+            return false;
+        }
+        else if (!(obj instanceof Request)) {
+            return false;
+        }
+
+        Request request = (Request) obj;
+
+        return getId().equals(request.getId());
+    }
+
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                .append("id", getId())
+                .append("signaled", signaled)
+                .append("message", message)
+                .toString();
+    }
+
+    public Message getMessage() {
+        return message;
+    }
+
+    public MessageID getId() {
+        return getMessage().getId();
+    }
+
+    public Duration getTimeout() {
+        return timeout;
+    }
+
+    public boolean hasResponse() {
+        return !responses.isEmpty();
+    }
+
+    public Response awaitResponse() throws RequestTimeoutException, InterruptedException {
+        chechEndOfResponses();
+
+        log.debug("Waiting for response");
+
+        Response resp = decodeResponse(responses.take());
+
+        log.trace("Received response: {}", resp);
+
+        return resp;
+    }
+
+    public Response awaitResponse(final long timeout, final TimeUnit unit) throws RequestTimeoutException, InterruptedException {
+        chechEndOfResponses();
+
+        log.debug("Polling for response");
+
+        Response resp = decodeResponse(responses.poll(timeout, unit));
+
+        if (log.isTraceEnabled()) {
+            if (resp != null) {
+                log.trace("Received response: {}", resp);
+            }
+            else {
+                log.trace("Operation timed out before the response was signaled");
+            }
+        }
+
+        return resp;
+    }
+
+    public Response awaitResponseUninterruptibly() throws RequestTimeoutException {
+        while (true) {
+            try {
+                return awaitResponse();
+            }
+            catch (InterruptedException ignore) {}
+        }
+    }
+
+    private Response decodeResponse(final Object obj) {
+        if (obj instanceof Response) {
+            return (Response) obj;
+        }
+        else if (obj == null) {
+            return null;
+        }
+        else if (obj == RequestTimeoutException.class) {
+            throw new RequestTimeoutException(getId());
+        }
+
+        // This should never happen
+        throw new InternalError();
+    }
+
+    private void chechEndOfResponses() {
+        if (endOfResponses && responses.isEmpty()) {
+            throw new IllegalStateException("All responses has been retrieved already");
+        }
+    }
+
+    private void queueResponse(final Object answer) {
+        signaled = true;
+
+        responses.add(answer);
+    }
+
+    void signal(final Response response) {
+        assert response != null;
+
+        lock.lock();
+
+        try {
+            if (log.isTraceEnabled()) {
+                log.debug("Signal response: {}", response);
+            }
+            else {
+                log.debug("Signal response: {}", response.getRequest().getId());
+            }
+
+            queueResponse(response);
+
+            if (response.getType() != Response.Type.PARTIAL) {
+                endOfResponses = true;
+            }
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    void timeout() {
+        lock.lock();
+
+        try {
+            log.debug("Timeout");
+
+            queueResponse(RequestTimeoutException.class);
+
+            endOfResponses = true;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    boolean isSignaled() {
+        lock.lock();
+
+        try {
+            return signaled;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,87 @@
+/*
+ * 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.whisper.request;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.spi.MessageMarshaller;
+import org.apache.geronimo.gshell.whisper.message.spi.MessageProvider;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+/**
+ * Encodes {@link Request} objects for protocl serialization handling.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestEncoder
+    implements org.apache.mina.filter.codec.demux.MessageEncoder
+{
+    @SuppressWarnings({"FieldCanBeLocal"})
+    private static final Set<Class<?>> MESSAGE_TYPES;
+
+    static {
+        Set<Class<?>> types = new HashSet<Class<?>>();
+
+        types.add(Request.class);
+
+        MESSAGE_TYPES = Collections.unmodifiableSet(types);
+    }
+
+    private final MessageProvider provider;
+
+    public RequestEncoder(final MessageProvider provider) {
+        this.provider = provider;
+    }
+
+    public Set<Class<?>> getMessageTypes() {
+        return MESSAGE_TYPES;
+    }
+
+    public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
+        Request request = (Request) message;
+
+        MessageMarshaller marshaller = provider.getMessageMarshaller();
+
+        Message msg = request.getMessage();
+
+        byte[] bytes = marshaller.marshal(msg);
+
+        out.write(ByteBuffer.wrap(bytes));
+    }
+
+    public static class Factory
+        implements org.apache.mina.filter.codec.demux.MessageEncoderFactory
+    {
+        private MessageProvider provider;
+
+        public Factory(final MessageProvider provider) {
+            this.provider = provider;
+        }
+
+        public org.apache.mina.filter.codec.demux.MessageEncoder getEncoder() throws Exception {
+            return new RequestEncoder(provider);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestEncoder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.whisper.request;
+
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestException
+    extends RuntimeException
+{
+    private static final long serialVersionUID = 1;
+
+    public RequestException(final MessageID id) {
+        super(String.valueOf(id));
+    }
+
+    public RequestException(final String msg, final Throwable cause) {
+        super(msg, cause);
+    }
+
+    public RequestException(final String msg) {
+        super(msg);
+    }
+
+    public RequestException(final Throwable cause) {
+        super(cause);
+    }
+
+    public RequestException() {
+        super();
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,339 @@
+/*
+ * 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.whisper.request;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.geronimo.gshell.common.Duration;
+import org.apache.geronimo.gshell.common.NamedThreadFactory;
+import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.apache.geronimo.gshell.whisper.session.SessionAttributeBinder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Manages request state on a per-session basis, handles timeouts and signalling responses.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestManager
+{
+    public static final SessionAttributeBinder<RequestManager> BINDER = new SessionAttributeBinder<RequestManager>(RequestManager.class);
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Map<MessageID,Registration> registrations = new HashMap<MessageID, Registration>();
+
+    private final ScheduledExecutorService scheduler;
+
+    //
+    // TODO: Use a better locking scheme...
+    //
+    
+    private final Lock lock = new ReentrantLock();
+
+    public RequestManager() {
+        ThreadFactory tf = new NamedThreadFactory(getClass());
+        
+        scheduler = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, tf);
+    }
+
+    private Registration get(final MessageID id) {
+        assert id != null;
+
+        Registration reg = registrations.get(id);
+
+        if (reg == null) {
+            throw new NotRegisteredException(id);
+        }
+
+        return reg;
+    }
+
+    private Registration remove(final MessageID id) {
+        assert id != null;
+
+        Registration reg = registrations.remove(id);
+
+        if (reg == null) {
+            throw new NotRegisteredException(id);
+        }
+
+        return reg;
+    }
+
+    public void register(final Request request) {
+        assert request != null;
+
+        lock.lock();
+
+        try {
+            MessageID id = request.getId();
+
+            if (registrations.containsKey(id)) {
+                throw new DuplicateRegistrationException(id);
+            }
+
+            Registration reg = new Registration(request);
+
+            registrations.put(id, reg);
+
+            log.debug("Registered: {}", reg);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public Request lookup(final MessageID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+
+            return reg.request;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public Request deregister(final MessageID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = remove(id);
+
+            reg.deactivate();
+
+            log.debug("Deregistered: {}", reg);
+
+            return reg.request;
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void activate(final MessageID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+            
+            reg.activate();
+
+            log.debug("Activated: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring activation; request not registered: {}", id);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void deactivate(final MessageID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = get(id);
+
+            reg.deactivate();
+
+            log.debug("Deactivated: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring deactivation; request not registered: {}", id);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    private void timeout(final MessageID id) {
+        assert id != null;
+
+        lock.lock();
+
+        try {
+            Registration reg = remove(id);
+
+            reg.timeout();
+
+            log.debug("Timed out: {}", reg);
+        }
+        catch (NotRegisteredException e) {
+            log.debug("Ignoring timeout; request not registered: {}", id);
+        }
+        catch (TimeoutAbortedException e) {
+            log.debug("Timeout aborted: " + e.getMessage());
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void close() {
+        lock.lock();
+
+        try {
+            if (!registrations.isEmpty()) {
+                log.warn("Timing out remaining {} registrations", registrations.size());
+
+                for (Registration reg : registrations.values()) {
+                    timeout(reg.request.getId());
+                }
+            }
+
+            //
+            // FIXME: This causes some problems when a rsh client closes, like:
+            //
+            //        java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThread)
+            //
+            // scheduler.shutdown();
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    private enum RegistrationState
+    {
+        PENDING,
+        ACTIVE,
+        DEACTIVE,
+        TIMEDOUT
+    }
+
+    private class Registration
+    {
+        public final Request request;
+
+        public RegistrationState state = RegistrationState.PENDING;
+
+        private ScheduledFuture<?> timeoutFuture;
+
+        public Registration(final Request request) {
+            assert request != null;
+
+            this.request = request;
+        }
+
+        public void activate() {
+            if (state != RegistrationState.PENDING) {
+                log.debug("Can not activate, state is not PENDING, found: {}", state);
+            }
+            else {
+                Runnable task = new Runnable() {
+                    public void run() {
+                        RequestManager.this.timeout(request.getId());
+                    }
+                };
+
+                Duration timeout = request.getTimeout();
+
+                log.debug("Scheduling timeout to trigger in: {}", timeout);
+
+                timeoutFuture = scheduler.schedule(task, timeout.getValue(), timeout.getUnit());
+
+                state = RegistrationState.ACTIVE;
+            }
+        }
+
+        public void deactivate() {
+            if (state != RegistrationState.ACTIVE) {
+                log.debug("Can not deactivate; state is not ACTIVE, found: {}", state);
+            }
+            else if (timeoutFuture.cancel(false)) {
+                timeoutFuture = null;
+
+                state = RegistrationState.DEACTIVE;
+            }
+            else {
+                log.warn("Unable to cancel registration timeout: {}", this);
+            }
+        }
+
+        public void timeout() {
+            MessageID id = request.getId();
+
+            if (timeoutFuture.isCancelled()) {
+                throw new TimeoutAbortedException("Timeout has been canceled: " + id);
+            }
+            else if (request.isSignaled()) {
+                throw new TimeoutAbortedException("Request has been singled: " + id);
+            }
+            else {
+                request.timeout();
+
+                state = RegistrationState.TIMEDOUT;
+            }
+        }
+
+        public String toString() {
+            return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                    .append("id", request.getId())
+                    .append("state", state)
+                    .toString();
+        }
+    }
+
+    public class NotRegisteredException
+        extends RequestException
+    {
+        public NotRegisteredException(final MessageID id) {
+            super(id);
+        }
+    }
+
+    public class DuplicateRegistrationException
+        extends RequestException
+    {
+        public DuplicateRegistrationException(final MessageID id) {
+            super(id);
+        }
+    }
+
+    public class TimeoutAbortedException
+        extends RequestException
+    {
+        public TimeoutAbortedException(final String msg) {
+            super(msg);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,128 @@
+/*
+ * 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.whisper.request;
+
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides synchronous request/response messaging.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestResponseFilter
+    extends IoFilterAdapter
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /**
+     * Set up the request manager instance for the session.
+     */
+    @Override
+    public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws Exception {
+        RequestManager.BINDER.bind(session, new RequestManager());
+
+        nextFilter.sessionCreated(session);
+    }
+
+    /**
+     * Close the request manager instance for the session.
+     */
+    @Override
+    public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws Exception {
+        RequestManager manager = RequestManager.BINDER.unbind(session);
+        
+        manager.close();
+
+        nextFilter.sessionClosed(session);
+    }
+
+    /**
+     * When a request is sent, register it with the request manager.
+     */
+    @Override
+    public void filterWrite(final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest) throws Exception {
+        Object message = writeRequest.getMessage();
+
+        if (message instanceof Request) {
+            Request request = (Request) message;
+
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            manager.register(request);
+        }
+
+        nextFilter.filterWrite(session, writeRequest);
+    }
+
+    /**
+     * When a response message has been received, deregister it and signal the response.
+     */
+    @Override
+    public void messageReceived(final NextFilter nextFilter, final IoSession session, final Object message) throws Exception {
+        Message msg = null;
+
+        MessageID id = null;
+
+        if (message instanceof Message) {
+            msg = (Message)message;
+
+            id = msg.getCorrelationId();
+        }
+
+        // If we have a correlation id, then we can process the response
+        if (id != null) {
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            Request request = manager.deregister(id);
+
+            // Setup the response and signal the request
+            Response response = new Response(request, msg, Response.Type.WHOLE);
+
+            request.signal(response);
+
+            // Do not pass on the response
+        }
+        else {
+            nextFilter.messageReceived(session, message);
+        }
+    }
+
+    /**
+     * Once the reqeust message has been sent then activate it.  Some times a message gets consumed before we get a chance
+     * to activate it, which is okay, the {@link RequestManager} will simply ignore the request.
+     */
+    @Override
+    public void messageSent(final NextFilter nextFilter, final IoSession session, final Object message) throws Exception {
+        if (message instanceof Request) {
+            Request request = (Request) message;
+
+            RequestManager manager = RequestManager.BINDER.lookup(session);
+
+            manager.activate(request.getId());
+        }
+
+        nextFilter.messageSent(session, message);
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.whisper.request;
+
+import org.apache.geronimo.gshell.whisper.message.MessageID;
+
+/**
+ * Thrown to indicate that a request has been timed out.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestTimeoutException
+    extends RequestException
+{
+    private static final long serialVersionUID = 1;
+
+    private final MessageID id;
+
+    public RequestTimeoutException(final MessageID id) {
+        super("Request timed out: " + id);
+
+        this.id = id;
+    }
+
+    public MessageID getId() {
+        return id;
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestTimeoutException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java?rev=578566&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java Sun Sep 23 05:02:46 2007
@@ -0,0 +1,155 @@
+/*
+ * 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.whisper.request;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.geronimo.gshell.common.Duration;
+import org.apache.geronimo.gshell.whisper.message.Message;
+import org.apache.geronimo.gshell.whisper.transport.Transport;
+import org.apache.mina.common.IoFutureListener;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides support to send a request and receive it's response.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Requestor
+{
+    public static final Duration DEFAULT_TIMEOUT = new Duration(10, TimeUnit.SECONDS);
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    private final IoSession session;
+
+    private final Duration timeout;
+
+    public Requestor(final IoSession session, final Duration timeout) {
+        this.session = session;
+        this.timeout = timeout;
+    }
+
+    public Requestor(final IoSession session) {
+        this(session, DEFAULT_TIMEOUT);
+    }
+
+    public Requestor(final Transport transport, final long timeout, final TimeUnit unit) {
+        this(transport.getSession(), new Duration(timeout, unit));
+    }
+
+    public Requestor(final Transport transport) {
+        this(transport.getSession(), DEFAULT_TIMEOUT);
+    }
+
+    public RequestWriteFuture submit(final Message msg, final long timeout, final TimeUnit unit) throws Exception {
+        assert msg != null;
+
+        Request req = new Request(msg, timeout, unit);
+
+        WriteFuture wf = session.write(req);
+
+        return new RequestWriteFuture(wf, req);
+    }
+
+    public RequestWriteFuture submit(final Message msg, final Duration timeout) throws Exception {
+        return submit(msg, timeout.getValue(), timeout.getUnit());
+    }
+
+    public RequestWriteFuture submit(final Message msg) throws Exception {
+        return submit(msg, timeout.getValue(), timeout.getUnit());
+    }
+
+    public Message request(final Message msg, final long timeout, final TimeUnit unit) throws Exception {
+        assert msg != null;
+
+        RequestWriteFuture wf = submit(msg, timeout, unit);
+
+        Request req = wf.getRequest();
+
+        Response resp = req.awaitResponse();
+
+        return resp.getMessage();
+    }
+
+    public Message request(final Message msg, final Duration timeout) throws Exception {
+        return request(msg, timeout.getValue(), timeout.getUnit());
+    }
+
+    public Message request(final Message msg) throws Exception {
+        return request(msg, timeout.getValue(), timeout.getUnit());
+    }
+    
+    //
+    // RequestWriteFuture
+    //
+
+    public class RequestWriteFuture
+        implements WriteFuture
+    {
+        private final WriteFuture delegate;
+
+        private final Request request;
+
+        public RequestWriteFuture(final WriteFuture wf, final Request req) {
+            this.delegate = wf;
+            this.request = req;
+        }
+
+        public Request getRequest() {
+            return request;
+        }
+
+        public boolean isWritten() {
+            return delegate.isWritten();
+        }
+
+        public void setWritten(final boolean written) {
+            delegate.setWritten(written);
+        }
+
+        public IoSession getSession() {
+            return delegate.getSession();
+        }
+
+        public void join() {
+            delegate.join();
+        }
+
+        public boolean join(final long timeout) {
+            return delegate.join(timeout);
+        }
+
+        public boolean isReady() {
+            return delegate.isReady();
+        }
+
+        public void addListener(final IoFutureListener listener) {
+            delegate.addListener(listener);
+        }
+
+        public void removeListener(final IoFutureListener listener) {
+            delegate.removeListener(listener);
+        }
+    }
+}
\ No newline at end of file

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message