geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r537063 - in /geronimo/sandbox/gcache/client: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/geronimo/ src/main/java/org/apache/geronimo/gcache/ src/main/java/org/apache/geronimo/gcach...
Date Fri, 11 May 2007 01:10:26 GMT
Author: jgenender
Date: Thu May 10 18:10:24 2007
New Revision: 537063

URL: http://svn.apache.org/viewvc?view=rev&rev=537063
Log:
Add client

Added:
    geronimo/sandbox/gcache/client/gcache-client.iml
    geronimo/sandbox/gcache/client/pom.xml
    geronimo/sandbox/gcache/client/src/
    geronimo/sandbox/gcache/client/src/main/
    geronimo/sandbox/gcache/client/src/main/java/
    geronimo/sandbox/gcache/client/src/main/java/org/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/ClientConfigBuilder.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GcacheClientConfiguration.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/JaxbGcacheClientConfigurationFactory.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java
    geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java
    geronimo/sandbox/gcache/client/src/main/resources/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/
    geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/tcp
    geronimo/sandbox/gcache/client/src/main/resources/gcache-client-config-default.xml
    geronimo/sandbox/gcache/client/src/main/xsd/
    geronimo/sandbox/gcache/client/src/main/xsd/catalog.cat
    geronimo/sandbox/gcache/client/src/main/xsd/gcache-client.xsd
    geronimo/sandbox/gcache/client/src/test/
    geronimo/sandbox/gcache/client/src/test/java/
    geronimo/sandbox/gcache/client/src/test/java/org/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/ClientConfigBuilderTest.java
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/
    geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java
    geronimo/sandbox/gcache/client/src/test/resources/
    geronimo/sandbox/gcache/client/src/test/resources/gcache-client-config.xml
    geronimo/sandbox/gcache/client/src/test/resources/log4j.xml

Added: geronimo/sandbox/gcache/client/gcache-client.iml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/gcache-client.iml?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/gcache-client.iml (added)
+++ geronimo/sandbox/gcache/client/gcache-client.iml Thu May 10 18:10:24 2007
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="false" type="JAVA_MODULE">
+  <component name="ModuleRootManager" />
+  <component name="NewModuleRootManager" inherit-compiler-output="false">
+    <output url="file://$MODULE_DIR$/target/classes" />
+    <exclude-output />
+    <output-test url="file://$MODULE_DIR$/target/test-classes" />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/target/generated-sources/jaxb" isTestSource="false" />
+      <excludeFolder url="file://$MODULE_DIR$/target/classes" />
+      <excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
+      <excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/backport-util-concurrent/backport-util-concurrent/2.2/backport-util-concurrent-2.2.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/org/apache/mina/mina-core/1.0.0/mina-core-1.0.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module" module-name="gcache-common" />
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/log4j/log4j/1.2.8/log4j-1.2.8.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/commons-collections/commons-collections/2.1/commons-collections-2.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/com/sun/xml/bind/jaxb-impl/2.0.3/jaxb-impl-2.0.3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/org/testng/testng/5.1/testng-5.1-jdk15.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar:///Users/jeffgenender/.m2/repository/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntryProperties />
+  </component>
+</module>
+

Added: geronimo/sandbox/gcache/client/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/pom.xml?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/pom.xml (added)
+++ geronimo/sandbox/gcache/client/pom.xml Thu May 10 18:10:24 2007
@@ -0,0 +1,62 @@
+<project>
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<parent>
+		<groupId>org.apache.geronimo.gcache</groupId>
+		<artifactId>gcache</artifactId>
+		<version>1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+	</parent>
+
+	<artifactId>gcache-client</artifactId>
+	<packaging>jar</packaging>
+
+	<name>GCache :: Client</name>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>com.sun.xml.bind</groupId>
+			<artifactId>jaxb-impl</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>javax.xml.bind</groupId>
+			<artifactId>jaxb-api</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>org.testng</groupId>
+			<artifactId>testng</artifactId>
+			<classifier>jdk15</classifier>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.apache.geronimo.gcache</groupId>
+			<artifactId>gcache-common</artifactId>
+		</dependency>
+
+		<dependency>
+			<groupId>net.sf.ehcache</groupId>
+			<artifactId>ehcache</artifactId>
+		</dependency>
+
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>jaxb2-maven-plugin</artifactId>
+				<configuration>
+					<catalog>${basedir}/src/main/xsd/catalog.cat</catalog>
+					<packageName>
+						org.apache.geronimo.gcache.client.dd
+					</packageName>
+					<extension>true</extension>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/ClientConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/ClientConfigBuilder.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/ClientConfigBuilder.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/ClientConfigBuilder.java Thu May 10 18:10:24 2007
@@ -0,0 +1,151 @@
+/*
+ * 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.client;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.DiskStoreConfiguration;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.client.dd.CacheType;
+import org.apache.geronimo.gcache.client.dd.DefaultCacheType;
+import org.apache.geronimo.gcache.client.dd.DiscoveryType;
+import org.apache.geronimo.gcache.client.dd.DiskStoreType;
+import org.apache.geronimo.gcache.client.dd.GcacheClientConfig;
+import org.apache.geronimo.gcache.client.dd.JaxbGcacheClientConfigurationFactory;
+import org.apache.geronimo.gcache.dd.GcacheConfiguration;
+
+public class ClientConfigBuilder {
+
+    private static final Log log = LogFactory.getLog(ClientConfigBuilder.class);
+
+    private static final String CLASSPATH_CONFIGURATION_FILE = "gcache-client-config.xml";
+
+    private static final String DEFAULT_CLASSPATH_CONFIGURATION_FILE = "gcache-client-config-default.xml";
+
+    public GcacheClientConfiguration getConfig(URL fileURL) {
+
+        GcacheClientConfiguration config = null;
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+        // Was a file passed to us?
+        if (fileURL != null) {
+            config = processConfig(fileURL);
+            return config;
+        }
+
+        // Is the configuration file in the path somewhere?
+        URL configURL = cl.getResource(CLASSPATH_CONFIGURATION_FILE);
+        if (configURL != null) {
+            config = processConfig(configURL);
+
+            return config;
+        }
+
+        // Read the default config
+        log.warn("Using " + DEFAULT_CLASSPATH_CONFIGURATION_FILE
+                + " for configuration. No cache configurations are loaded.  Please consider having your own.");
+
+        configURL = cl.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE);
+        if (configURL == null) {
+            throw new RuntimeException(DEFAULT_CLASSPATH_CONFIGURATION_FILE + " not found, not configuration can be loaded.");
+        }
+        config = processConfig(configURL);
+        return config;
+    }
+
+    private GcacheClientConfiguration processConfig(URL url) {
+        try {
+            GcacheClientConfiguration gcacheClientConfig = new GcacheClientConfiguration();
+            Configuration ehcacheConfig = new Configuration();
+            DiskStoreConfiguration diskConfig = null;
+            CacheConfiguration defaultCache = null;
+
+            JaxbGcacheClientConfigurationFactory factory = new JaxbGcacheClientConfigurationFactory();
+
+            GcacheClientConfig config = factory.getConfig(url);
+
+            // Get the discovery
+            DiscoveryType discovery = config.getDiscovery();
+            if (discovery != null) {
+                gcacheClientConfig.setUser(discovery.getUser());
+                gcacheClientConfig.setPassword(discovery.getPassword());
+
+                URI discoveryURI = new URI(discovery.getUri());
+                gcacheClientConfig.setDiscoveryUri(discoveryURI);
+
+            }
+
+            // Read the disk store
+            DiskStoreType diskStore = config.getDiskStore();
+            if (diskStore != null) {
+                String path = diskStore.getPath();
+                diskConfig = new DiskStoreConfiguration();
+                diskConfig.setPath(path);
+            }
+
+            // Read the default cache
+            DefaultCacheType defaultType = config.getDefaultCache();
+            if (defaultType != null) {
+                defaultCache = new CacheConfiguration();
+                defaultCache.setDiskExpiryThreadIntervalSeconds(defaultType.getDiskExpiryThreadIntervalSeconds());
+                defaultCache.setMaxElementsInMemory(defaultType.getMaxElementsInMemory());
+                defaultCache.setEternal(defaultType.isEternal());
+                defaultCache.setDiskPersistent(defaultType.isDiskPersistent());
+                defaultCache.setOverflowToDisk(defaultType.isOverflowToDisk());
+                defaultCache.setTimeToIdleSeconds(defaultType.getTimeToIdleSeconds());
+                defaultCache.setTimeToLiveSeconds(defaultType.getTimeToLiveSeconds());
+                defaultCache.setMemoryStoreEvictionPolicy(defaultType.getMemoryStoreEvictionPolicy());
+            }
+
+            ehcacheConfig.setDefaultCacheConfiguration(defaultCache);
+            ehcacheConfig.addDiskStore(diskConfig);
+
+            // Read the cache list
+            List<CacheType> cacheList = config.getCaches();
+            for (CacheType cacheType : cacheList) {
+                CacheConfiguration cache = new CacheConfiguration();
+                cache.setName(cacheType.getName());
+                cache.setDiskExpiryThreadIntervalSeconds(cacheType.getDiskExpiryThreadIntervalSeconds());
+                cache.setMaxElementsInMemory(cacheType.getMaxElementsInMemory());
+                cache.setEternal(cacheType.isEternal());
+                cache.setDiskPersistent(cacheType.isDiskPersistent());
+                cache.setOverflowToDisk(cacheType.isOverflowToDisk());
+                cache.setTimeToIdleSeconds(cacheType.getTimeToIdleSeconds());
+                cache.setTimeToLiveSeconds(cacheType.getTimeToLiveSeconds());
+                cache.setMemoryStoreEvictionPolicy(cacheType.getMemoryStoreEvictionPolicy());
+
+                ehcacheConfig.addCache(cache);
+            }
+
+            gcacheClientConfig.setEhcacheConfig(ehcacheConfig);
+
+            return gcacheClientConfig;
+
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GCacheClient.java Thu May 10 18:10:24 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.gcache.client;
+
+import java.io.File;
+
+import net.sf.ehcache.CacheManager;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.dd.GcacheConfiguration;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
+import org.apache.geronimo.gcache.transports.ConnectionManager;
+import org.apache.geronimo.gcache.transports.tcp.TCPClientCommandVisitor;
+
+public class GCacheClient {
+    
+    private String configFile;
+    private CacheInfoHolder info;
+    private CacheManager cacheMgr;
+    private ClientConnectionManager connectionManager;
+
+    public GCacheClient(String configFile) {
+        super();
+        this.configFile = configFile;
+    }
+
+    public void start() throws Exception {
+        // Create a cache with the configuration from the gcache-config file
+        ClientConfigBuilder builder = new ClientConfigBuilder();
+
+        GcacheClientConfiguration config = builder.getConfig(configFile == null ? null : (new File(configFile)).toURL());
+        
+        cacheMgr = new CacheManager(config.getEhcacheConfig());
+        cacheMgr = new CacheManager();
+        info = new CacheInfoHolder(cacheMgr);
+        info.setCommandVisitor(new TCPClientCommandVisitor(info));
+        
+        connectionManager = new ClientConnectionManager(info);
+        connectionManager.setDiscoveryURI(config.getDiscoveryUri());
+        connectionManager.setUserName(config.getUser());
+        connectionManager.setPassword(config.getPassword());
+        connectionManager.start();
+
+    }
+    
+    public void stop() throws Exception{
+        connectionManager.stop();
+    }
+
+    public void put(String session, Object key, Object value) {
+    }
+
+    public void get(String session, Object key) {
+
+    }
+
+    public void remove(String session, Object key) {
+
+    }
+    
+    public void lock(String session, Object key) {
+        connectionManager.waitForConnection();
+        //TODO: Add lock calls here
+    }
+    
+    public void release(String session, Object key) {
+
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GcacheClientConfiguration.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GcacheClientConfiguration.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GcacheClientConfiguration.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/GcacheClientConfiguration.java Thu May 10 18:10:24 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.client;
+
+import java.net.URI;
+
+import org.apache.geronimo.gcache.dd.GcacheConfiguration;
+
+public class GcacheClientConfiguration extends GcacheConfiguration {
+    
+    private String user;
+    private String password;
+    private URI discoveryUri;
+    
+    public URI getDiscoveryUri() {
+        return discoveryUri;
+    }
+    public void setDiscoveryUri(URI discoveryUri) {
+        this.discoveryUri = discoveryUri;
+    }
+    public String getPassword() {
+        return password;
+    }
+    public void setPassword(String password) {
+        this.password = password;
+    }
+    public String getUser() {
+        return user;
+    }
+    public void setUser(String user) {
+        this.user = user;
+    }
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/JaxbGcacheClientConfigurationFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/JaxbGcacheClientConfigurationFactory.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/JaxbGcacheClientConfigurationFactory.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/client/dd/JaxbGcacheClientConfigurationFactory.java Thu May 10 18:10:24 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.gcache.client.dd;
+
+import java.net.URL;
+
+import org.apache.geronimo.gcache.dd.JaxbConfigFactory;
+
+public class JaxbGcacheClientConfigurationFactory extends JaxbConfigFactory {
+
+    public static final String SCHEMA = "http://geronimo.apache.org/xml/ns/gcache-client-1.0";
+    
+    public GcacheClientConfig getConfig(URL url) throws Exception {
+        return getConfig(url, GcacheClientConfig.class);
+    }
+
+    @Override
+    public String getSchema() {
+        return SCHEMA;
+    }
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientConnectionManager.java Thu May 10 18:10:24 2007
@@ -0,0 +1,242 @@
+/*
+ * 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.net.URISyntaxException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryAgentFactory;
+
+public class ClientConnectionManager extends ConnectionManager {
+
+    private static Log log = LogFactory.getLog(ClientConnectionManager.class);
+
+    private boolean stopped = true;
+
+    AtomicBoolean connected = new AtomicBoolean(false);
+    
+    private Object connectionLatch = new Object();
+
+    private ConnectionMonitor monitor;
+
+    public ClientConnectionManager(CacheInfoHolder info) {
+        super(info);
+    }
+
+    @Override
+    public void start() throws Exception {
+
+        stopped = false;
+
+        if (discoveryURI != null) {
+            discovery = DiscoveryAgentFactory.createDiscoveryAgent(discoveryURI, info);
+        }
+
+        if (discovery != null)
+            discovery.start();
+
+        monitor = new ConnectionMonitor(this);
+        monitor.start();
+
+    }
+
+    @Override
+    public void stop() throws Exception {
+
+        stopped = true;
+
+        // Shut down the connection monitor
+        monitor.signal();
+
+        if (discovery != null)
+            discovery.stop();
+
+        if (transport != null) {
+            transport.stop();
+        }
+
+    }
+
+    public boolean isConnected() {
+        return connected.get();
+    }
+
+    public void waitForConnection() {
+        if (!isConnected()) {
+            try {
+                synchronized(connectionLatch){
+                    connectionLatch.wait();
+                }
+            } catch (InterruptedException e) {
+                log.error(e);
+            }
+        }
+    }
+
+    public void onDisconnect() throws Exception {
+        // Signal the monitor to get a connection
+        connected.set(false);
+        monitor.signal();
+    }
+
+    private void connectToServer() {
+        DiscoveryManager disc = info.getDiscoveryManager();
+        while (!stopped) {
+            String services[] = disc.getServices();
+
+            // If nobody is out there, then sleep for a second to listen for
+            // servers
+            if (services.length == 0) {
+                sleeper(1000);
+                continue;
+            }
+
+            // TODO - We need to identify the master here!!!!
+
+            // Ok, we have some servers, lets go for the first one in line
+            URI uri = null;
+            try {
+                uri = new URI(services[0]);
+            } catch (URISyntaxException e) {
+                // This should never happen
+                log.error(e);
+                // Take a nap
+                sleeper(1000);
+                // And try again
+                continue;
+            }
+
+            transportURI = uri;
+            try {
+                if (log.isDebugEnabled()) {
+                    log.debug("Attempting to connect client to " + transportURI.toASCIIString());
+                }
+                transport = ClientTransportFactory.createTransportService(transportURI, info, this);
+            } catch (IOException e) {
+                transport = null;
+                log.error(e);
+                // Take a nap
+                sleeper(1000);
+                // And try again
+                continue;
+            }
+            transport.setUserName(userName);
+            transport.setPassword(password);
+
+            try {
+                transport.start();
+                int tries = 0;
+
+                // Try to connect 3 times
+                while (!((ClientTransportService) transport).connect()) {
+                    if (tries++ > 2)
+                        break;
+                    sleeper(500);
+                }
+                if (tries > 2) {
+                    log.error("Unable to connect to " + transportURI);
+                    continue;
+                }
+
+                // Now authenticate
+                if (!((ClientTransportService) transport).join()) {
+                    log.error("Unable to authenticate to " + transportURI.toASCIIString());
+                    continue;
+                }
+                
+                connected.set(true);
+                synchronized(connectionLatch){
+                    connectionLatch.notifyAll();
+                }
+                
+            } catch (Exception e) {
+                transport = null;
+                log.error(e);
+                // Take a nap
+                sleeper(1000);
+                // And try again
+                continue;
+            }
+
+            return;
+
+        }
+    }
+
+    private void sleeper(int millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {
+            // This really should not ever happen
+            log.error(e);
+        }
+    }
+
+    class ConnectionMonitor extends Thread {
+        private Object monitor = new Object();
+
+        private ClientConnectionManager mgr;
+
+        public ConnectionMonitor(ClientConnectionManager mgr) {
+            super();
+            this.mgr = mgr;
+        }
+
+        public void signal() {
+            // Shut down the old transport
+            if (transport != null) {
+                try {
+                    transport.stop();
+                } catch (Exception e) {
+                    log.error(e);
+                }
+            }
+
+            // Signal the monitor to reconnect
+            synchronized (monitor) {
+                monitor.notify();
+            }
+        }
+
+        @Override
+        public void run() {
+            do {
+                mgr.connectToServer();
+
+                synchronized (monitor) {
+                    try {
+                        monitor.wait();
+                    } catch (InterruptedException e) {
+                        // We are done
+                        return;
+                    }
+                }
+
+            } while (!stopped);
+
+        }
+
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportFactory.java Thu May 10 18:10:24 2007
@@ -0,0 +1,65 @@
+/*
+ * 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 ClientTransportFactory {
+
+        static final private FactoryFinder transportFactoryFinder = new FactoryFinder("META-INF/services/org/apache/geronimo/gcache/client/transport/");
+        static final private ConcurrentHashMap transportFactorys = new ConcurrentHashMap();
+
+        /**
+         * @param location
+         * @return
+         * @throws IOException
+         */
+        private static ClientTransportFactory findTransportFactory(URI location) throws IOException {
+            String scheme = location.getScheme();
+            if( scheme == null )
+                throw new IOException("Transport not scheme specified: [" + location + "]");
+            ClientTransportFactory tf = (ClientTransportFactory) transportFactorys.get(scheme);
+            if (tf == null) {
+                // Try to load if from a META-INF property.
+                try {
+                    tf = (ClientTransportFactory) 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, ClientConnectionManager connectionManager) throws IOException{
+            ClientTransportFactory tf = findTransportFactory(uri);
+            return tf.doCreateTransportService(uri, info, connectionManager);
+
+        }
+        
+        abstract protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info, ClientConnectionManager connectionManager) throws IOException;
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/ClientTransportService.java Thu May 10 18:10:24 2007
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.transports;
+
+public interface ClientTransportService {
+    
+    public boolean connect();
+
+    public void putSession(String cacheName, String sessionId, Object value);
+
+    public void putEntry(String cacheName, String sessionId, Object key, Object value);
+
+    public void removeSession(String cacheName, String session);
+
+    public void removeEntry(String cacheName, String sessionId, Object key);
+
+    public boolean join();
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/DisconnectionException.java Thu May 10 18:10:24 2007
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+public class DisconnectionException extends Exception {
+
+    private static final long serialVersionUID = -111080993146368517L;
+
+    public DisconnectionException() {
+        super();
+    }
+
+    public DisconnectionException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DisconnectionException(String message) {
+        super(message);
+    }
+
+    public DisconnectionException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: 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=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientCommandVisitor.java Thu May 10 18:10:24 2007
@@ -0,0 +1,181 @@
+/*
+ * 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;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.geronimo.gcache.command.ErrorCommand;
+import org.apache.geronimo.gcache.command.GetSessionCommand;
+import org.apache.geronimo.gcache.command.LockAcquiredCommand;
+import org.apache.geronimo.gcache.command.LockCommand;
+import org.apache.geronimo.gcache.command.LockReleasedCommand;
+import org.apache.geronimo.gcache.command.MessageAckCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.ReleaseLockCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+import org.apache.mina.common.IoSession;
+
+public class TCPClientCommandVisitor extends BaseCommandVisitor {
+
+    private CacheInfoHolder infoHolder;
+
+    public TCPClientCommandVisitor(CacheInfoHolder infoHolder) {
+        super();
+        this.infoHolder = infoHolder;
+    }
+
+    public void processPutSession(PutSessionCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        cache.put(new Element(command.getSessionId(), command.getPayload()));
+
+        sendAck(command);
+
+    }
+
+    @SuppressWarnings( { "unchecked" })
+    public void processPutEntry(PutEntryCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        // Check if we are using sessions
+        if (command.hasSession()) {
+
+            Map sessionMap = null;
+
+            // We are so use the session maps that is stored
+            Element element = cache.get(command.getSessionId());
+            if (element != null) {
+                sessionMap = (Map) element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.put(command.getHashableKey(), command.getPayload());
+            // Put the session away
+            cache.put(new Element(command.getSessionId(), sessionMap));
+
+        } else {
+
+            // No session map so store the value
+            cache.put(new Element(command.getHashableKey(), command.getPayload()));
+        }
+
+        sendAck(command);
+    }
+
+    public void processMessageAck(MessageAckCommand command) {
+        // This should never get called as the filters will handle it
+    }
+    
+    public void processGetSession(GetSessionCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+        Object key = cache.get(command.getSessionId());
+        Element element = cache.get(key);
+        
+    }
+
+    public void processBulkSend(BulkSendCommand command) {
+
+        // Get the command count and set the attribute to count em down
+        int commandCount = command.getNumberOfCommands();
+
+        IoSession sess = (IoSession) command.getAttachment();
+        if (sess == null)
+            return;
+
+        // Setup the BulkCommand filter to process bulk commands
+        sess.setAttribute(Constants.BULK_COUNT + command.getCommandId(), commandCount);
+        sess.setAttribute(Constants.BULK_COMMAND_ID + command.getCommandId());
+
+        // Do not send an ack here, the filter will send it once all
+        // of the following commands have been received
+    }
+
+    public void processRemoveEntry(RemoveEntryCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        // Check if we are using sessions
+        if (command.hasSession()) {
+
+            Map sessionMap = null;
+
+            // We are so use the session maps that is stored
+            Element element = cache.get(command.getSessionId());
+            if (element != null) {
+                sessionMap = (Map) element.getObjectValue();
+            } else {
+                sessionMap = Collections.synchronizedMap(new HashMap());
+            }
+
+            sessionMap.remove(command.getKey());
+
+            // Put the session away
+            cache.put(new Element(command.getSessionId(), sessionMap));
+
+        } else {
+
+            // No session map so remove the value
+            cache.remove(command.getHashableKey());
+        }
+
+        sendAck(command);
+    }
+
+    public void processRemoveSession(RemoveSessionCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        // Be sure a session was sent
+        if (command.hasSession()) {
+            cache.remove(command.getSessionId());
+        }
+
+        sendAck(command);
+    }
+
+    public void processLockAcquired(LockAcquiredCommand command) {
+        // TODO - Fill in
+    }
+
+    public void processLockSession(LockCommand command) {
+        // TODO - Fill in
+    }
+
+    public void processReleaseLockSession(ReleaseLockCommand command) {
+        // TODO - Fill in
+    }
+
+    public void processError(ErrorCommand command) {
+        // TODO - Fill in
+    }
+
+    public void processLockReleased(LockReleasedCommand command) {
+        // TODO - Fill in
+    }
+    
+ 
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketHandler.java Thu May 10 18:10:24 2007
@@ -0,0 +1,93 @@
+/*
+ * 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.concurrent.ConcurrentHashMap;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+
+public class TCPClientSocketHandler extends TCPSocketHandler {
+    ConcurrentHashMap<Long, TCPReceiverFuture> receivers = new ConcurrentHashMap<Long, TCPReceiverFuture>();
+    ClientConnectionManager connectionManager;
+
+    public TCPClientSocketHandler(CacheInfoHolder infoHolder, ClientConnectionManager connectionManager, int threadPoolSize) {
+        super(infoHolder, threadPoolSize);
+        this.connectionManager = connectionManager;
+    }
+
+    public TCPClientSocketHandler(CacheInfoHolder infoHolder, ClientConnectionManager connectionManager) {
+        super(infoHolder);
+        this.connectionManager = connectionManager;
+    }
+
+    @Override
+    public void exceptionCaught(IoSession arg0, Throwable arg1) throws Exception {
+    }
+
+    @Override
+    public void sessionClosed(IoSession sess) throws Exception {
+        //Clean up any open receivers by forcing a disconnect
+        for (Long key : receivers.keySet()) {
+            TCPReceiverFuture receiver = receivers.remove(key);
+            if (receiver != null){
+                receiver.disconnect();
+            }            
+        }
+        connectionManager.onDisconnect();
+    }
+
+    @Override
+    public void messageReceived(IoSession session, Object obj) throws Exception {
+
+        Command command = (Command) obj;
+        
+        //Lookup and remove if we have a receiver
+        TCPReceiverFuture receiver = receivers.remove(command.getCommandId());
+        
+        //If we have a receiver, process the answer directly to the client
+        if (receiver != null) {
+            receiver.setResponse(command);
+            return;
+        }
+        
+        //Otherwise process the answer with the visitor
+        command.setAttachment(session);
+        command.execute(infoHolder.getCommandVisitor());
+
+    }
+
+    public TCPReceiverFuture synchronousSend(IoSession sess, BaseCommand command) {
+        TCPReceiverFuture receiver = new TCPReceiverFuture();
+        command.getCommandId();
+        receivers.put(command.getCommandId(), receiver);
+        WriteFuture future = sess.write(command);
+
+        // Wait for it to be written
+        future.join();
+
+        return receiver;
+
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportService.java Thu May 10 18:10:24 2007
@@ -0,0 +1,254 @@
+/*
+ * 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.security.PublicKey;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gcache.command.AuthCommand;
+import org.apache.geronimo.gcache.command.AuthSuccessfulCommand;
+import org.apache.geronimo.gcache.command.BaseCommand;
+import org.apache.geronimo.gcache.command.Command;
+import org.apache.geronimo.gcache.command.HandShakeCommand;
+import org.apache.geronimo.gcache.command.PublicKeyCommand;
+import org.apache.geronimo.gcache.command.PutEntryCommand;
+import org.apache.geronimo.gcache.command.PutSessionCommand;
+import org.apache.geronimo.gcache.command.RemoveEntryCommand;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
+import org.apache.geronimo.gcache.transports.ClientTransportService;
+import org.apache.geronimo.gcache.transports.DisconnectionException;
+import org.apache.geronimo.gcache.util.CipherUtil;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
+
+public class TCPClientSocketTransportService extends TCPTransportService implements ClientTransportService {
+
+    private static Log log = LogFactory.getLog(TCPClientSocketTransportService.class);
+
+    private boolean stopped = true;
+
+    private IoHandler handler;
+
+    private IoSession sess;
+    
+    private String userId = "system";
+    
+    private String password = "manager";
+    
+    private ClientConnectionManager connectionManager;
+
+    @Override
+    public void start() throws Exception {
+        stopped = false;
+    }
+
+    @Override
+    public void stop() throws Exception {
+        stopped = true;
+        disconnect();
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public void setConnectionManager(ClientConnectionManager connectionManager) {
+        this.connectionManager = connectionManager;
+    }
+
+    public boolean connect() {
+        // Get the proper attributes
+        int port = tcpURI.getPort();
+        String host = tcpURI.getHost();
+
+        // Create an address
+        InetSocketAddress address = new InetSocketAddress(host, port);
+
+        if (sess != null && sess.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 TCPClientSocketHandler(info, connectionManager);
+            
+
+            ConnectFuture future = connector.connect(address, handler, cfg);
+            future.join();
+            if (!future.isConnected()) {
+                return false;
+            }
+            sess = future.getSession();
+
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    private void disconnect() {
+        if (sess != null) {
+//            if (sess.isConnected()) {
+//                sess.getCloseFuture().join();
+//            }
+            sess.close();
+            sess = null;
+        }
+    }
+
+    public boolean join() {
+        
+        //Send a handshake and introduce myself
+        HandShakeCommand command = new HandShakeCommand();
+        command.setPublicKey(CipherUtil.publicKey);
+        try {
+            Command response = sendAndReceive(command);
+            if (!(response instanceof PublicKeyCommand)) {
+                log.error("Response expected a PublicKeyCommand and received a " + response.getClass().getSimpleName() + " instead.");
+                return false;
+            }
+            
+            //Expect a PublicKey from the server
+            PublicKey serverKey = ((PublicKeyCommand)response).getPublicKey();
+            
+            //Send auth credentials
+            AuthCommand auth = new AuthCommand();
+            auth.setPassword(password);
+            auth.setUserId(userId);
+            auth.setPublicKey(serverKey);
+            response = sendAndReceive(auth);
+            if (!(response instanceof AuthSuccessfulCommand)) {
+                log.error("Response expected a PublicKeyCommand and received a " + response.getClass().getSimpleName() + " instead.");
+                return false;
+            }
+            
+        }catch (DisconnectionException e) {
+            log.error(e);
+            return false;
+        }catch (TimeoutException e) {
+            log.error(e);
+            return false;
+        } catch (InterruptedException e) {
+            log.error(e);
+            return false;
+        } catch (ExecutionException e) {
+            log.error(e);
+            return false;
+        }
+
+        return true;
+    }
+
+    public void putSession(String cacheName, String sessionId, Object value) {
+
+        PutSessionCommand command = new PutSessionCommand();
+
+        command.setCacheName(cacheName);
+        command.setSessionId(sessionId);
+        command.setKey(value);
+        command.setPayload(value);
+
+        send(command);
+    }
+
+    public void removeEntry(String cacheName, String sessionId, Object key) {
+        RemoveEntryCommand command = new RemoveEntryCommand();
+
+        command.setCacheName(cacheName);
+        command.setSessionId(sessionId);
+        command.setKey(key);
+
+        send(command);
+    }
+
+    public void removeSession(String cacheName, String session) {
+        PutSessionCommand command = new PutSessionCommand();
+
+        command.setCacheName(cacheName);
+        command.setSessionId(session);
+
+        send(command);
+    }
+
+    public void putEntry(String cacheName, String sessionId, Object key, Object value) {
+
+        PutEntryCommand command = new PutEntryCommand();
+
+        command.setCacheName(cacheName);
+        command.setSessionId(sessionId);
+        command.setKey(value);
+        command.setPayload(value);
+
+        send(command);
+    }
+
+    public void send(BaseCommand command) {
+
+        WriteFuture future = sess.write(command);
+
+        // Request ack if setup to do so
+        command.setAttachment(sess);
+        ((TCPClientCommandVisitor) info.getCommandVisitor()).requestAck(command);
+
+        // Wait for it to be written
+        future.join();
+
+    }
+
+    private Command sendAndReceive(BaseCommand command) throws InterruptedException, ExecutionException, TimeoutException, DisconnectionException {
+        TCPClientSocketHandler handler = (TCPClientSocketHandler) sess.getHandler();
+        TCPReceiverFuture future = handler.synchronousSend(sess, command);
+        //TODO: Offer a timeout
+        return (Command) future.get();
+    }
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactory.java Thu May 10 18:10:24 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.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.ClientConnectionManager;
+import org.apache.geronimo.gcache.transports.ClientTransportFactory;
+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 TCPClientSocketTransportServiceFactory extends ClientTransportFactory {
+
+    @Override
+    protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info, ClientConnectionManager connectionManager) throws IOException {
+        try {
+
+            Map options = URISupport.parseParamters(uri);
+            TCPClientSocketTransportService rc = new TCPClientSocketTransportService();
+
+            rc.setInfo(info);
+            rc.setTcpURI(uri);
+            rc.setConnectionManager(connectionManager);
+            IntrospectionSupport.setProperties(rc, options);
+            return rc;
+
+        } catch (Throwable e) {
+            throw IOExceptionSupport.create("Could not create tcp transport service: " + uri, e);
+        }
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java (added)
+++ geronimo/sandbox/gcache/client/src/main/java/org/apache/geronimo/gcache/transports/tcp/TCPReceiverFuture.java Thu May 10 18:10:24 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.geronimo.gcache.transports.DisconnectionException;
+
+public class TCPReceiverFuture{
+    
+    private CountDownLatch latch = new CountDownLatch(1);
+    private Object response;
+    
+    
+    private AtomicBoolean done = new AtomicBoolean(false);
+    private AtomicBoolean disconnected = new AtomicBoolean(false);
+
+    public Object get() throws InterruptedException, ExecutionException, DisconnectionException {
+        latch.await();
+        if (disconnected.get())
+            throw new DisconnectionException();
+        return response;
+    }
+
+    public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException, DisconnectionException {
+        latch.await(timeout, unit);
+        if (disconnected.get())
+            throw new DisconnectionException();
+        return response;
+    }
+
+    public boolean isDone() {
+        return done.get();
+    }
+
+    public void setResponse(Object response) {
+        this.response = response;
+        done.set(false);
+        latch.countDown();
+    }
+    
+    protected void disconnect(){
+        disconnected.set(true);
+        latch.countDown();
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/tcp
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/tcp?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/tcp (added)
+++ geronimo/sandbox/gcache/client/src/main/resources/META-INF/services/org/apache/geronimo/gcache/client/transport/tcp Thu May 10 18:10:24 2007
@@ -0,0 +1 @@
+class=org.apache.geronimo.gcache.transports.tcp.TCPClientSocketTransportServiceFactory
\ No newline at end of file

Added: geronimo/sandbox/gcache/client/src/main/resources/gcache-client-config-default.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/resources/gcache-client-config-default.xml?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/resources/gcache-client-config-default.xml (added)
+++ geronimo/sandbox/gcache/client/src/main/resources/gcache-client-config-default.xml Thu May 10 18:10:24 2007
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gcache-client-config>
+	<discovery user="system" password="manager" uri="multicast://default" />
+	<diskStore path="${java.io.tmpdir}/gcache" />
+	<defaultCache maxElementsInMemory="10000" eternal="false"
+		timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
+		diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
+		memoryStoreEvictionPolicy="LRU" />
+</gcache-client-config>
\ No newline at end of file

Added: geronimo/sandbox/gcache/client/src/main/xsd/catalog.cat
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/xsd/catalog.cat?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/xsd/catalog.cat (added)
+++ geronimo/sandbox/gcache/client/src/main/xsd/catalog.cat Thu May 10 18:10:24 2007
@@ -0,0 +1 @@
+SYSTEM "http://geronimo.apache.org/xml/ns/gcache-1.0.xsd" "../../../../common/src/main/xsd/gcache.xsd"

Added: geronimo/sandbox/gcache/client/src/main/xsd/gcache-client.xsd
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/main/xsd/gcache-client.xsd?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/main/xsd/gcache-client.xsd (added)
+++ geronimo/sandbox/gcache/client/src/main/xsd/gcache-client.xsd Thu May 10 18:10:24 2007
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema
+	xmlns:gcache-client="http://geronimo.apache.org/xml/ns/gcache-client-1.0"
+	xmlns:gcache="http://geronimo.apache.org/xml/ns/gcache-1.0"
+	xmlns:xs="http://www.w3.org/2001/XMLSchema"
+	xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
+	xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
+	targetNamespace="http://geronimo.apache.org/xml/ns/gcache-client-1.0"
+	jxb:version="2.0"	
+	jxb:extensionBindingPrefixes="xjc"
+	elementFormDefault="qualified" attributeFormDefault="unqualified">
+	
+	<xs:annotation>
+   		<xs:appinfo>
+   			<jxb:globalBindings>
+    			<xjc:simple />
+    		</jxb:globalBindings>
+    	</xs:appinfo>
+    </xs:annotation>
+
+	<xs:import namespace="http://geronimo.apache.org/xml/ns/gcache-1.0" schemaLocation="http://geronimo.apache.org/xml/ns/gcache-1.0.xsd"/>
+
+	<xs:element name="gcache-client-config"
+		type="gcache-client:gcacheClientConfig" />
+
+	<xs:complexType name="gcacheClientConfig">
+		<xs:sequence>
+			<xs:element name="discovery" type="gcache-client:discoveryType"
+				minOccurs="1" maxOccurs="1" />
+			<xs:element name="diskStore" type="gcache:diskStoreType"
+				minOccurs="1" maxOccurs="1" />
+			<xs:element name="defaultCache"
+				type="gcache:defaultCacheType" minOccurs="1" maxOccurs="1" />
+			<xs:element name="cache" type="gcache:cacheType"
+				minOccurs="0" maxOccurs="unbounded" />
+		</xs:sequence>
+	</xs:complexType>
+	
+	<xs:complexType name="discoveryType">
+		<xs:attribute name="user" use="optional" type="xs:NCName" default="system"/>
+		<xs:attribute name="password" use="optional" type="xs:NCName" default="manager"/>
+		<xs:attribute name="uri" use="optional" type="xs:NCName" />
+	</xs:complexType>
+
+</xs:schema>
\ No newline at end of file

Added: geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/ClientConfigBuilderTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/ClientConfigBuilderTest.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/ClientConfigBuilderTest.java (added)
+++ geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/dd/ClientConfigBuilderTest.java Thu May 10 18:10:24 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.dd;
+
+import java.util.Map;
+
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+
+import org.apache.geronimo.gcache.client.ClientConfigBuilder;
+import org.apache.geronimo.gcache.client.GcacheClientConfiguration;
+import org.testng.annotations.Test;
+
+public class ClientConfigBuilderTest {
+
+    @Test
+    public void testConfigBuilder() throws Exception {
+        ClientConfigBuilder cb = new ClientConfigBuilder();
+
+        //Pull the configuration
+        GcacheClientConfiguration config = cb.getConfig(null);
+
+        //Discovery settings
+        assert config.getUser().equals("system");
+        assert config.getPassword().equals("manager");
+        assert config.getDiscoveryUri().getHost().equals("default");
+        assert config.getDiscoveryUri().getScheme().equals("multicast");
+
+        //Check for cache configs
+        Configuration ehcacheConfig = config.getEhcacheConfig();
+        assert ehcacheConfig != null;
+
+        Map configs = ehcacheConfig.getCacheConfigurations();
+        assert configs.containsKey("Test");
+        assert configs.containsKey("Test2");
+
+        //Test cache detail info
+        CacheConfiguration cacheConfig = (CacheConfiguration) configs.get("Test");
+        assert 60 == cacheConfig.getDiskExpiryThreadIntervalSeconds();
+        assert 1800 == cacheConfig.getTimeToIdleSeconds();
+        assert cacheConfig.getMemoryStoreEvictionPolicy().toString().equals("LRU");
+        assert 0 == cacheConfig.getTimeToLiveSeconds();
+
+        //Test a default cache was configured
+        CacheConfiguration defaultConfig = ehcacheConfig.getDefaultCacheConfiguration();
+        assert 120 == defaultConfig.getDiskExpiryThreadIntervalSeconds();
+        assert 120 == defaultConfig.getTimeToIdleSeconds();
+        assert defaultConfig.getMemoryStoreEvictionPolicy().toString().equals("LRU");
+        assert 120 == defaultConfig.getTimeToLiveSeconds();
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java (added)
+++ geronimo/sandbox/gcache/client/src/test/java/org/apache/geronimo/gcache/transports/tcp/TCPClientSocketTransportServiceFactoryTest.java Thu May 10 18:10:24 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.URI;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.transports.ClientConnectionManager;
+import org.testng.annotations.Test;
+
+public class TCPClientSocketTransportServiceFactoryTest {
+    
+    @Test
+    public void testTCPClientSocketTransportServiceFactory() throws Exception{
+        
+        CacheInfoHolder info = new CacheInfoHolder(null);
+        ClientConnectionManager mgr = new ClientConnectionManager(info);
+        URI uri = new URI("tcp://default");
+        TCPClientSocketTransportService service = (TCPClientSocketTransportService)TCPClientSocketTransportServiceFactory.createTransportService(uri, info, mgr);
+        
+        assert service instanceof TCPClientSocketTransportService;
+        assert service != null;
+    }
+
+}

Added: geronimo/sandbox/gcache/client/src/test/resources/gcache-client-config.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/resources/gcache-client-config.xml?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/resources/gcache-client-config.xml (added)
+++ geronimo/sandbox/gcache/client/src/test/resources/gcache-client-config.xml Thu May 10 18:10:24 2007
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gcache-client-config>
+	<discovery user="system" password="manager" uri="multicast://default" />
+	
+	<diskStore path="${java.io.tmpdir}/gcache" />
+	
+	<defaultCache maxElementsInMemory="10000" eternal="false"
+		timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"
+		diskPersistent="false" diskExpiryThreadIntervalSeconds="120"
+		memoryStoreEvictionPolicy="LRU" />
+		
+	<cache name="Test" maxElementsInMemory="10000" eternal="false"
+		timeToIdleSeconds="1800" timeToLiveSeconds="0" overflowToDisk="true"
+		diskPersistent="false" diskExpiryThreadIntervalSeconds="60"
+		memoryStoreEvictionPolicy="LRU" />
+		
+	<cache name="Test2" maxElementsInMemory="10000" eternal="false"
+		timeToIdleSeconds="0" timeToLiveSeconds="1800" overflowToDisk="false"
+		diskPersistent="true" diskExpiryThreadIntervalSeconds="60"
+		memoryStoreEvictionPolicy="LFU" />
+</gcache-client-config>

Added: geronimo/sandbox/gcache/client/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/client/src/test/resources/log4j.xml?view=auto&rev=537063
==============================================================================
--- geronimo/sandbox/gcache/client/src/test/resources/log4j.xml (added)
+++ geronimo/sandbox/gcache/client/src/test/resources/log4j.xml Thu May 10 18:10:24 2007
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+	<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
+		<layout class="org.apache.log4j.PatternLayout">
+			<!--param name="ConversionPattern" value="[%p] %c %m%n"/-->
+			<param name="ConversionPattern" value="[%p] [%c{1}] %m%n"/>
+		</layout>
+	</appender>
+
+   <category name="net.sf.ehcache.config.ConfigurationFactory">
+      <priority value="ERROR"/>
+   </category>
+
+	<root>
+		<priority value="debug"/>
+		<appender-ref ref="ConsoleAppender"/>
+	</root>
+
+</log4j:configuration>
\ No newline at end of file



Mime
View raw message