geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r480290 - in /geronimo/sandbox/gcache: client/src/main/java/org/apache/geronimo/gcache/transports/tcp/ common/src/main/java/org/apache/geronimo/gcache/transports/network/ common/src/main/java/org/apache/geronimo/gcache/transports/tcp/ serve...
Date Tue, 28 Nov 2006 23:49:00 GMT
Author: jgenender
Date: Tue Nov 28 15:48:59 2006
New Revision: 480290

URL: http://svn.apache.org/viewvc?view=rev&rev=480290
Log:
Refactor API for sharing on client and server

Added:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientTransportService.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
  (contents, props changed)
      - copied, changed from r477589, geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPTransportService.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerConnectionManager.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerTransportFactory.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketHandler.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportService.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportServiceFactory.java
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/
    geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/tcp
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
  (contents, props changed)
      - copied, changed from r477589, geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServiceTest.java
Removed:
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportService.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketTransportServiceFactory.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServiceTest.java
Modified:
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
    geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
    geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
    geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java
    geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java

Modified: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java?view=diff&rev=480290&r1=480289&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
(original)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
Tue Nov 28 15:48:59 2006
@@ -1,3 +1,21 @@
+/*
+ * 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.gcache.transports.tcp;
 
 import java.util.Collections;

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientTransportService.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientTransportService.java
(added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientTransportService.java
Tue Nov 28 15:48:59 2006
@@ -0,0 +1,108 @@
+/*
+ * 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.gcache.transports.tcp;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
+import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
+
+public class TCPClientTransportService extends TCPTransportService {
+
+    private IoHandler handler;
+
+    private IoSession session;
+
+    @Override
+    public void start() throws Exception {
+        int port = tcpURI.getPort();
+        String host = tcpURI.getHost();
+
+        InetSocketAddress inet = new InetSocketAddress(host, port);
+
+        connect(inet);
+    }
+
+    @Override
+    public void stop() throws Exception {
+        disconnect();
+    }
+
+    private boolean connect(SocketAddress address) {
+
+        if (session != null && session.isConnected()) {
+            throw new IllegalStateException("Already connected. Disconnect first.");
+        }
+
+        try {
+
+            SocketConnector connector = new SocketConnector();
+            SocketConnectorConfig cfg = new SocketConnectorConfig();
+
+            // If we requested logging, add that too
+            if (enableLogging) {
+                cfg.getFilterChain().addLast("logFilter", new LoggingFilter());
+            }
+
+            // Add the filter to handle the GCache Codec
+            cfg.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new TCPCommandProtocolCodecFactory()));
+
+            // Add the BulkCommandFilter for filtering when a BulkCommand is
+            // being read
+            cfg.getFilterChain().addLast(TCPBulkCommandFilter.NAME, new TCPBulkCommandFilter());
+
+            // If we require message acks, then set up the message ack filter
+            if (requireMessageAck) {
+                cfg.getFilterChain().addLast(TCPMessageAckCommandFilter.NAME, new TCPMessageAckCommandFilter(ackTimeout));
+            }
+
+            handler = new TCPSocketHandler(info);
+
+            ConnectFuture future1 = connector.connect(address, handler, cfg);
+            future1.join();
+            if (!future1.isConnected()) {
+                return false;
+            }
+            session = future1.getSession();
+
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    private void disconnect() {
+        if (session != null) {
+            if (session.isConnected()) {
+                session.getCloseFuture().join();
+            }
+            session.close();
+            session = null;
+        }
+    }
+
+}

Copied: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
(from r477589, geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java?view=diff&rev=480290&p1=geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java&r1=477589&p2=geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/ConnectionManager.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
Tue Nov 28 15:48:59 2006
@@ -26,7 +26,7 @@
 
 import java.net.URI;
 
-public class ConnectionManager{
+public class NetworkConnectionManager{
 
     private CacheInfoHolder info;
     private URI transportURI;
@@ -36,7 +36,7 @@
     private String nodeName;
     private int order;
 
-    public ConnectionManager(CacheInfoHolder info){
+    public NetworkConnectionManager(CacheInfoHolder info){
         this.info = info;
     }
 

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/network/NetworkConnectionManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java?view=diff&rev=480290&r1=480289&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
(original)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketHandler.java
Tue Nov 28 15:48:59 2006
@@ -33,8 +33,8 @@
 public class TCPSocketHandler extends IoHandlerAdapter {
 
     public final static int DEFAULT_THREAD_POOL_SIZE = 10;
-    private final CacheInfoHolder infoHolder;
-    private final ScheduledThreadPoolExecutor scheduler;
+    protected final CacheInfoHolder infoHolder;
+    protected final ScheduledThreadPoolExecutor scheduler;
 
     public TCPSocketHandler(final CacheInfoHolder infoHolder) {
         this(infoHolder, DEFAULT_THREAD_POOL_SIZE);
@@ -61,20 +61,6 @@
         command.setAttachment(session);
         command.execute(infoHolder.getCommandVisitor());
 
-    }
-
-    @Override
-    public void exceptionCaught(IoSession sess, Throwable cause) throws Exception {
-        SessionLog.error(sess, "", cause);
-        infoHolder.getEndpointManager().removeEndpoint(sess);
-        sess.close();
-    }
-
-
-    @Override
-    public void sessionClosed(IoSession sess) throws Exception {
-        //Remove the client from the list
-        infoHolder.getEndpointManager().removeEndpoint(sess);
     }
 
     public void destroy() {

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPTransportService.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPTransportService.java
(added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPTransportService.java
Tue Nov 28 15:48:59 2006
@@ -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.gcache.transports.tcp;
+
+import java.net.InetAddress;
+import java.net.URI;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.transports.TransportService;
+
+public abstract class TCPTransportService extends TransportService {
+
+    private final static Log log = LogFactory.getLog(TCPTransportService.class);
+
+    public static final int DEFAULT_PORT = 4123;
+    public static final long DEFAULT_ACK_TIMEOUT = 10000;
+    public final static String DEFAULT_USERNAME = "system";
+    public final static String DEFAULT_PASSWORD = "manager";
+
+    protected URI tcpURI;
+    protected boolean requireMessageAck = false;
+    protected boolean enableLogging = false;
+    protected long ackTimeout = DEFAULT_ACK_TIMEOUT;
+    protected TCPSocketHandler handler = null;
+    protected String userId = DEFAULT_USERNAME;
+    protected String password = DEFAULT_PASSWORD;
+
+    public String getService() throws Exception{
+        if (tcpURI == null){
+            throw new Exception("TCP URI has not been set.");
+        }
+
+        String host = tcpURI.getHost();
+        if (host.equals("0.0.0.0")){
+            host = InetAddress.getLocalHost().getHostAddress().toString();
+        }
+        return tcpURI.getScheme() + "://" + host + ":" + tcpURI.getPort();
+    }
+
+    public URI getTcpURI() {
+        return tcpURI;
+    }
+
+    public void setTcpURI(URI tcpURI) throws Exception{
+        int port = tcpURI.getPort();
+        if (port == -1){
+            port = DEFAULT_PORT;
+        }
+        if (tcpURI.getHost().equals("default")){
+            String query = tcpURI.getQuery();
+            String uri = tcpURI.getScheme() + "://" + "0.0.0.0" + ":" + port + (query ==
null ? "" : "?" + query); 
+            this.tcpURI = new URI(uri);
+        } else {
+            this.tcpURI = tcpURI;
+        }
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public boolean isRequireMessageAck() {
+        return requireMessageAck;
+    }
+
+    public void setRequireMessageAck(boolean requireMessageAck) {
+        this.requireMessageAck = requireMessageAck;
+    }
+
+    public long getAckTimeout() {
+        return ackTimeout;
+    }
+
+    public void setAckTimeout(long ackTimeout) {
+        this.ackTimeout = ackTimeout;
+    }
+
+    public boolean isEnableLogging() {
+        return enableLogging;
+    }
+
+    public void setEnableLogging(boolean enableLogging) {
+        this.enableLogging = enableLogging;
+    }
+
+}

Modified: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java?view=diff&rev=480290&r1=480289&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
(original)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/server/GCacheManager.java
Tue Nov 28 15:48:59 2006
@@ -30,7 +30,7 @@
 import org.apache.geronimo.gcache.CacheInfoHolder;
 import org.apache.geronimo.gcache.dd.ConfigBuilder;
 import org.apache.geronimo.gcache.dd.GcacheConfiguration;
-import org.apache.geronimo.gcache.transports.network.ConnectionManager;
+import org.apache.geronimo.gcache.transports.ServerConnectionManager;
 import org.apache.geronimo.gcache.transports.tcp.TCPCacheNotifier;
 import org.apache.geronimo.gcache.transports.tcp.TCPCommandVisitor;
 
@@ -40,7 +40,7 @@
     private String configFile;
     private CacheInfoHolder info;
     private CacheManager cacheMgr;
-    private ConnectionManager connectionManager;
+    private ServerConnectionManager connectionManager;
 
     public GCacheManager(String configFile) {
         this.configFile = configFile;
@@ -57,7 +57,7 @@
         info.setCommandVisitor(new TCPCommandVisitor(info));
         info.setCacheNotifier(new TCPCacheNotifier());
 
-        connectionManager = new ConnectionManager(info);
+        connectionManager = new ServerConnectionManager(info);
         connectionManager.setTransportURI(config.getTransportUri());
         connectionManager.setDiscoveryURI(config.getDiscoveryUri());
         connectionManager.setOrder(config.getOrder());

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerConnectionManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerConnectionManager.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerConnectionManager.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerConnectionManager.java
Tue Nov 28 15:48:59 2006
@@ -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.gcache.transports;
+
+import java.net.URI;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgent;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
+
+public class ServerConnectionManager {
+    private CacheInfoHolder info;
+
+    private URI transportURI;
+
+    private URI discoveryURI;
+
+    private TransportService transport;
+
+    private DiscoveryAgent discovery;
+
+    private String nodeName;
+
+    private int order;
+
+    public ServerConnectionManager(CacheInfoHolder info) {
+        this.info = info;
+    }
+
+    public void start() throws Exception {
+        transport = ServerTransportFactory.createTransportService(transportURI, info);
+        if (discoveryURI != null) {
+            discovery = DiscoveryAgentFactory.createDiscoveryAgent(discoveryURI, info);
+            discovery.registerService(transport.getService());
+            discovery.setNodeName(nodeName);
+            discovery.setOrder(order);
+        }
+
+        transport.start();
+
+        if (discovery != null)
+            discovery.start();
+    }
+
+    public void stop() throws Exception {
+
+        if (discovery != null)
+            discovery.stop();
+
+        if (transport != null) {
+            transport.stop();
+        }
+    }
+
+    public void setTransportURI(URI transportURI) {
+        this.transportURI = transportURI;
+    }
+
+    public void setDiscoveryURI(URI discoveryURI) {
+        this.discoveryURI = discoveryURI;
+    }
+
+    public void setNodeName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    public void setOrder(int order) {
+        this.order = order;
+    }
+
+}

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerTransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerTransportFactory.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerTransportFactory.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/ServerTransportFactory.java
Tue Nov 28 15:48:59 2006
@@ -0,0 +1,64 @@
+/*
+ * 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.gcache.transports;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.FactoryFinder;
+import org.apache.geronimo.gcache.util.IOExceptionSupport;
+
+public abstract class ServerTransportFactory {
+    static final private FactoryFinder transportFactoryFinder = new FactoryFinder("META-INF/services/org/apache/geronimo/gcache/server/transport/");
+    static final private ConcurrentHashMap transportFactorys = new ConcurrentHashMap();
+
+    /**
+     * @param location
+     * @return
+     * @throws IOException
+     */
+    private static ServerTransportFactory findTransportFactory(URI location) throws IOException
{
+        String scheme = location.getScheme();
+        if( scheme == null )
+            throw new IOException("Transport not scheme specified: [" + location + "]");
+        ServerTransportFactory tf = (ServerTransportFactory) transportFactorys.get(scheme);
+        if (tf == null) {
+            // Try to load if from a META-INF property.
+            try {
+                tf = (ServerTransportFactory) transportFactoryFinder.newInstance(scheme);
+                transportFactorys.put(scheme, tf);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("Transport scheme NOT recognized: [" + scheme
+ "]", e);
+            }
+        }
+        return tf;
+    }
+    
+    public static TransportService createTransportService(URI uri, CacheInfoHolder info)
throws IOException {
+        ServerTransportFactory tf = findTransportFactory(uri);
+        return tf.doCreateTransportService(uri, info);
+
+    }
+    
+    abstract protected TransportService doCreateTransportService(URI uri, CacheInfoHolder
info) throws IOException;
+
+}

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketHandler.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketHandler.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketHandler.java
Tue Nov 28 15:48:59 2006
@@ -0,0 +1,50 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.gcache.transports.tcp;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.util.SessionLog;
+
+/**
+ * This class is the main worker of the gcache functionality. Essentialy this
+ */
+public class TCPServerSocketHandler extends TCPSocketHandler {
+
+    public TCPServerSocketHandler(CacheInfoHolder infoHolder, int threadPoolSize) {
+        super(infoHolder, threadPoolSize);
+    }
+
+    public TCPServerSocketHandler(CacheInfoHolder infoHolder) {
+        super(infoHolder);
+    }
+
+    @Override
+    public void exceptionCaught(IoSession sess, Throwable cause) throws Exception {
+        SessionLog.error(sess, "", cause);
+        infoHolder.getEndpointManager().removeEndpoint(sess);
+        sess.close();
+    }
+
+
+    @Override
+    public void sessionClosed(IoSession sess) throws Exception {
+        //Remove the client from the list
+        infoHolder.getEndpointManager().removeEndpoint(sess);
+    }
+
+}

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportService.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportService.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportService.java
Tue Nov 28 15:48:59 2006
@@ -0,0 +1,86 @@
+/*
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed 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.gcache.transports.tcp;
+
+import java.net.InetSocketAddress;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
+
+public class TCPServerSocketTransportService extends TCPTransportService {
+
+    private final static Log log = LogFactory.getLog(TCPServerSocketTransportService.class);
+
+    IoAcceptor acceptor = null;
+
+    public void start() throws Exception {
+        int port = tcpURI.getPort();
+        String host = tcpURI.getHost();
+
+        InetSocketAddress inet = new InetSocketAddress(host, port);
+
+        acceptor = new SocketAcceptor();
+        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
+        cfg.setReuseAddress(true);
+
+        //If we requested logging, add that too
+        if (enableLogging) {
+            cfg.getFilterChain().addLast("logFilter", new LoggingFilter());
+        }
+
+        //Add the filter to hande the GCache Codec
+        cfg.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new TCPCommandProtocolCodecFactory()));
+
+        //Add the authentication filter
+        cfg.getFilterChain().addLast(TCPAuthenticationFilter.NAME, new TCPAuthenticationFilter(userId,
password));
+
+        //Add the BulkCommandFilter for filtering when a BulkCommand is being read
+        cfg.getFilterChain().addLast(TCPBulkCommandFilter.NAME, new TCPBulkCommandFilter());
+
+        //If we require message acks, then set up the message ack filter
+        if (requireMessageAck) {
+            cfg.getFilterChain().addLast(TCPMessageAckCommandFilter.NAME, new TCPMessageAckCommandFilter(ackTimeout));
+        }
+
+
+        handler = new TCPServerSocketHandler(info);
+        acceptor.bind(inet, handler, cfg);
+    }
+
+    public void stop() throws Exception {
+
+        if (handler != null) {
+            try {
+                handler.destroy();
+                handler = null;
+            } catch (Exception e) {
+                log.error(e);
+                //Ignore since there is not much that can be done
+            }
+        }
+        if (acceptor != null) {
+            acceptor.unbindAll();
+            acceptor = null;
+        }
+    }
+
+}

Added: geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportServiceFactory.java?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportServiceFactory.java
(added)
+++ geronimo/sandbox/gcache/server/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketTransportServiceFactory.java
Tue Nov 28 15:48:59 2006
@@ -0,0 +1,50 @@
+/**
+ *
+ * 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.gcache.transports.tcp;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.ServerTransportFactory;
+import org.apache.geronimo.gcache.transports.TransportService;
+import org.apache.geronimo.gcache.util.IOExceptionSupport;
+import org.apache.geronimo.gcache.util.IntrospectionSupport;
+import org.apache.geronimo.gcache.util.URISupport;
+
+public class TCPServerSocketTransportServiceFactory extends ServerTransportFactory {
+
+    @Override
+    protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info) throws
IOException {
+        try {
+
+            Map options = URISupport.parseParamters(uri);
+            TCPServerSocketTransportService rc = new TCPServerSocketTransportService();
+
+            rc.setInfo(info);
+            rc.setTcpURI(uri);
+            IntrospectionSupport.setProperties(rc, options);
+            return rc;
+
+        } catch (Throwable e) {
+            throw IOExceptionSupport.create("Could not create tcp transport service: " +
uri, e);
+        }
+    }
+
+}

Added: geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/tcp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/tcp?view=auto&rev=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/tcp
(added)
+++ geronimo/sandbox/gcache/server/src/main/resources/META-INF/services/org/apache/geronimo/gcache/server/transport/tcp
Tue Nov 28 15:48:59 2006
@@ -0,0 +1 @@
+class=org.apache.geronimo.gcache.transports.tcp.TCPServerSocketTransportServiceFactory
\ No newline at end of file

Modified: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java?view=diff&rev=480290&r1=480289&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/AbstractService.java
Tue Nov 28 15:48:59 2006
@@ -42,7 +42,7 @@
     //protected String protocol = "tcp://localhost:45678";
     protected String protocol = "tcp://default?enableLogging=true";
 
-    protected TCPSocketTransportService server = null;
+    protected TCPServerSocketTransportService server = null;
 
     protected Socket client;
 
@@ -60,7 +60,7 @@
         info.setCommandVisitor(new TCPCommandVisitor(info));
         info.setCacheNotifier(new TCPCacheNotifier());
 
-        server = (TCPSocketTransportService)TCPSocketTransportServiceFactory.createTransportService(uri,
info);
+        server = (TCPServerSocketTransportService)TCPServerSocketTransportServiceFactory.createTransportService(uri,
info);
         
         server.setAckTimeout(10000);
         server.setRequireMessageAck(true);

Copied: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
(from r477589, geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServiceTest.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java?view=diff&rev=480290&p1=geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServiceTest.java&r1=477589&p2=geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPSocketServiceTest.java
(original)
+++ geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
Tue Nov 28 15:48:59 2006
@@ -25,7 +25,7 @@
 import org.apache.geronimo.gcache.command.PutSessionCommand;
 import org.testng.annotations.Test;
 
-public class TCPSocketServiceTest extends AbstractService {
+public class TCPServerSocketServiceTest extends AbstractService {
 
     @Test()
     public void sendSession()  throws Exception {

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/sandbox/gcache/server/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPServerSocketServiceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java?view=diff&rev=480290&r1=480289&r2=480290
==============================================================================
--- geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java
(original)
+++ geronimo/sandbox/gcache/tests/src/test/java/org/apache/geronimo/gcache/AbstractParent.java
Tue Nov 28 15:48:59 2006
@@ -2,7 +2,6 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -21,7 +20,6 @@
 import org.apache.mina.common.ByteBuffer;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
 
 public class AbstractParent{
     GCacheManager mgr;



Mime
View raw message