You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2006/11/09 19:23:31 UTC

svn commit: r473002 [2/3] - in /geronimo/sandbox/gcache: ./ common/ common/src/ common/src/main/ common/src/main/java/ common/src/main/java/org/ common/src/main/java/org/apache/ common/src/main/java/org/apache/geronimo/ common/src/main/java/org/apache/...

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.marshal;
+
+import org.apache.mina.common.ByteBuffer;
+
+/**
+ * Implementing this interface provides a way to optimize serilazation for
+ * distributed caching scenarios. If simply implementing java.io.Serializable
+ * provides sufficient performance then do that because its much simpler.
+ * 
+ * Implementors of this interface are expected to write/read any state into the
+ * channel that is provided. The read and write methods should read and write
+ * the data in the same order.
+ * 
+ * The gcache uses this interface to serialize and deserialize objects around
+ * the distributed cache. If this interface is not implemented the framework
+ * will revert to using java.io.Serializable to do the (de)serialization.
+ */
+public interface MarshalAware {
+    /**
+     * Read data from <code>channel</code> to reconstitute the object. The
+     * data is read in the same order it was written in the writeExternal
+     * method.
+     * 
+     * @param channel
+     * @throws Exception
+     */
+    void readExternal(ByteBuffer buffer) throws Exception;
+    
+    /**
+     * Write data into <code>channel</code> to save the state of the object.
+     * The data should be written in the same order it is expected in the
+     * readExternal method.
+     * 
+     * @param channel
+     * @throws Exception
+     */
+    void writeExternal(ByteBuffer buffer) throws Exception;
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/marshal/MarshalAware.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/BaseCommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/BaseCommandVisitor.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/BaseCommandVisitor.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/BaseCommandVisitor.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,68 @@
+package org.apache.geronimo.gcache.transports;
+
+import java.io.IOException;
+
+import net.sf.ehcache.Cache;
+
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+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.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+
+public class BaseCommandVisitor implements CommandVisitor {
+    protected CacheInfoHolder infoHolder;
+
+    public BaseCommandVisitor(CacheInfoHolder infoHolder) {
+        this.infoHolder = infoHolder;
+    }
+
+    public void processBulkSend(BulkSendCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processClearCache(ClearCacheCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processGetCache(GetCacheCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processMessageAck(MessageAckCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processPutEntry(PutEntryCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processPutSession(PutSessionCommand command) throws IOException {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void processRemoveEntry(RemoveEntryCommand command) {
+        Cache cache = infoHolder.getCache(command.getCacheName(), true);
+
+        // Be sure a session was sent
+        if (command.hasSession()) {
+            cache.remove(command.getSessionId());
+        }
+    }
+
+    public void processRemoveSession(RemoveSessionCommand command) {
+        // TODO Auto-generated method stub
+
+    }
+
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/CommandVisitor.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.geronimo.gcache.command.BulkSendCommand;
+import org.apache.geronimo.gcache.command.ClearCacheCommand;
+import org.apache.geronimo.gcache.command.GetCacheCommand;
+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.RemoveEntryCommand;
+import org.apache.geronimo.gcache.command.RemoveSessionCommand;
+
+import java.io.IOException;
+
+public interface CommandVisitor {
+
+    public void processRemoveSession(RemoveSessionCommand command);
+    public void processRemoveEntry(RemoveEntryCommand command);
+    public void processPutSession(PutSessionCommand command) throws IOException;
+    public void processPutEntry(PutEntryCommand command);
+    public void processMessageAck(MessageAckCommand command);
+    public void processGetCache(GetCacheCommand command);
+    public void processClearCache(ClearCacheCommand command);
+    public void processBulkSend(BulkSendCommand command);
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Constants.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Constants.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Constants.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Constants.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.transports;
+
+public class Constants {
+    public final static byte MAGIC[] = new byte[]{'G', 'C', 'a', 'c', 'h', 'e'};
+    public final static int HEADER_SIZE = MAGIC.length + 1 + 4;
+    
+    //Session attribute keys
+    public final static String AUTHENTICATED = "AUTHENTICATED";
+    public final static String AUTH_TASK = "AUTH_TASK";
+    public final static String BULK_COUNT = "BULK_COUNT_";
+    public final static String BULK_COMMAND_ID = "BULK_COMMAND_ID_";
+    public final static String MESSAGE_ACK_ID = "MESSAGE_ACK_ID_";
+    public final static String REMOTE_PUBLIC_KEY = "REMOTE_PUBLIC_KEY";
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/DiscoveryManager.java Thu Nov  9 10:23:28 2006
@@ -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.transports;
+
+import org.apache.geronimo.gcache.command.DiscoveryCommand;
+import org.apache.geronimo.gcache.transports.discovery.DiscoveryListener;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.*;
+
+public class DiscoveryManager implements DiscoveryListener {
+
+    private static final Log log = LogFactory.getLog(DiscoveryManager.class);
+
+    private Map index = Collections.synchronizedMap(new HashMap());
+    private Map services = Collections.synchronizedSortedMap(new TreeMap());
+    private static Long sequence = System.currentTimeMillis();
+
+    public String[] getServices() {
+        Collection c = services.values();
+        return (String[])c.toArray(new String[c.size()]);
+    }
+
+    public void onServiceAdd(DiscoveryCommand command) {
+
+        if (log.isDebugEnabled()){
+            log.debug("Adding node:" + command.getNodeName() + " registering " + command.getService());
+        }
+        //Remove if it already exists
+        onServiceRemove(command);
+
+        long indexNo = command.getOrder();
+        if (command.getOrder() == 0) {
+            synchronized (sequence) {
+                indexNo = sequence++;
+            }
+        }
+        
+        services.put(indexNo, command.getService());
+        index.put(command.getNodeName(), indexNo);
+    }
+
+    public void onServiceRemove(DiscoveryCommand command) {
+        Long indexNo = (Long) index.get(command.getNodeName());
+        if (indexNo != null) {
+            services.remove(indexNo);
+            index.remove(command.getNodeName());
+        }
+    }
+
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/Endpoint.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,22 @@
+/**
+ *
+ * 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 Endpoint {
+
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/EndpointManager.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,48 @@
+/**
+ *
+ * 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.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class EndpointManager {
+    
+    Set<Endpoint> endpoints = Collections.synchronizedSet(new HashSet<Endpoint>());
+    
+    public void addEndpoint(Endpoint endpoint){
+	endpoints.add(endpoint);
+    }
+    
+    public void removeEndpoint(Endpoint endpoint){
+	endpoints.remove(endpoint);
+    }
+    
+    public boolean contains(Endpoint endpoint){
+	return endpoints.contains(endpoint);
+    }
+    
+    public int size(){
+	return endpoints.size();
+    }
+
+    public Set<Endpoint> getEndpoints() {
+        return endpoints;
+    }
+    
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportFactory.java Thu Nov  9 10:23:28 2006
@@ -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 org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.FactoryFinder;
+import org.apache.geronimo.gcache.util.IOExceptionSupport;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+public abstract class TransportFactory {
+    
+    static final private FactoryFinder transportFactoryFinder = new FactoryFinder("META-INF/services/org/apache/geronimo/gcache/transport/");
+    static final private ConcurrentHashMap transportFactorys = new ConcurrentHashMap();
+
+    /**
+     * @param location
+     * @return
+     * @throws IOException
+     */
+    private static TransportFactory findTransportFactory(URI location) throws IOException {
+        String scheme = location.getScheme();
+        if( scheme == null )
+            throw new IOException("Transport not scheme specified: [" + location + "]");
+        TransportFactory tf = (TransportFactory) transportFactorys.get(scheme);
+        if (tf == null) {
+            // Try to load if from a META-INF property.
+            try {
+                tf = (TransportFactory) 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 {
+        TransportFactory tf = findTransportFactory(uri);
+        return tf.doCreateTransportService(uri, info);
+
+    }
+    
+    abstract protected TransportService doCreateTransportService(URI uri, CacheInfoHolder info) throws IOException;
+
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/TransportService.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.geronimo.gcache.CacheInfoHolder;
+
+
+public abstract class TransportService {
+    protected CacheInfoHolder info;
+    
+    public CacheInfoHolder getInfo() {
+        return info;
+    }
+    
+    public void setInfo(CacheInfoHolder info) {
+        this.info = info;
+    }
+
+    public abstract String getService() throws Exception;
+    public abstract void start() throws Exception;
+    public abstract void stop() throws Exception;
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgent.java Thu Nov  9 10:23:28 2006
@@ -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.transports.discovery;
+
+import java.io.IOException;
+
+import org.apache.geronimo.gcache.command.DiscoveryCommand;
+import org.apache.geronimo.gcache.transports.TransportService;
+
+public abstract class DiscoveryAgent extends TransportService {
+    /**
+     * Sets the discovery listener
+     * @param listener
+     */
+    public abstract void setDiscoveryListener(DiscoveryListener listener);
+
+    /**
+     * register a service
+     * @param name
+     * @throws IOException
+     */
+    public abstract void registerService(String name) throws IOException;
+    
+    /**
+     * A process actively using a service may see it go down before the DiscoveryAgent notices the
+     * service's failure.  That process can use this method to notify the DiscoveryAgent of the failure
+     * so that other listeners of this DiscoveryAgent can also be made aware of the failure.
+     */
+    public abstract void serviceFailed(DiscoveryCommand command) throws IOException;
+
+    public abstract void setNodeName(String name);
+
+    public abstract void setOrder(int order);
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryAgentFactory.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,63 @@
+/**
+ *
+ * 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.discovery;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.apache.geronimo.gcache.util.FactoryFinder;
+import org.apache.geronimo.gcache.CacheInfoHolder;
+import org.apache.geronimo.gcache.util.IOExceptionSupport;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+public abstract class DiscoveryAgentFactory {
+    static final private FactoryFinder discoveryAgentFinder = new FactoryFinder("META-INF/services/org/apache/geronimo/gcache/transport/discovery/");    
+    static final private ConcurrentHashMap discoveryAgentFactorys = new ConcurrentHashMap();
+
+    /**
+     * @param uri
+     * @return
+     * @throws IOException
+     */
+    private static DiscoveryAgentFactory findDiscoveryAgentFactory(URI uri) throws IOException {
+        String scheme = uri.getScheme();
+        if( scheme == null )
+            throw new IOException("DiscoveryAgent scheme not specified: [" + uri + "]");
+        DiscoveryAgentFactory daf = (DiscoveryAgentFactory) discoveryAgentFactorys.get(scheme);
+        if (daf == null) {
+            // Try to load if from a META-INF property.
+            try {
+                daf = (DiscoveryAgentFactory) discoveryAgentFinder.newInstance(scheme);
+                discoveryAgentFactorys.put(scheme, daf);
+            }
+            catch (Throwable e) {
+                throw IOExceptionSupport.create("DiscoveryAgent scheme NOT recognized: [" + scheme + "]", e);
+            }
+        }
+        return daf;
+    }
+    
+    public static DiscoveryAgent createDiscoveryAgent(URI uri, CacheInfoHolder info) throws IOException {
+        DiscoveryAgentFactory tf = findDiscoveryAgentFactory(uri);
+        return tf.doCreateDiscoveryAgent(uri, info);
+
+    }
+
+    abstract protected DiscoveryAgent doCreateDiscoveryAgent(URI uri, CacheInfoHolder info) throws IOException;
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/transports/discovery/DiscoveryListener.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,25 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.gcache.transports.discovery;
+
+import org.apache.geronimo.gcache.command.DiscoveryCommand;
+
+public interface DiscoveryListener {
+    public void onServiceAdd(DiscoveryCommand command);
+    public void onServiceRemove(DiscoveryCommand command);
+}

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

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

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,177 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
+
+/**
+ * Provides an input stream to read a socket channel and fill a buffer
+ */
+public class BufferChannelInputStream extends InputStream {
+
+    private SocketChannel channel = null;
+    private ByteBuffer buffer = null;
+    private long timeout = 10000;
+
+    public BufferChannelInputStream(SocketChannel channel, ByteBuffer buffer) {
+        this.channel = channel;
+        this.buffer = buffer;
+        buffer.flip();
+    }
+
+    public long getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(long timeout) {
+        this.timeout = timeout;
+    }
+
+    /**
+     * Read's next byte of data
+     *
+     * @return next byte of data or -1 if it cannot read
+     * @throws IOException
+     */
+    public int read() throws IOException {
+
+        //Have we read everything?
+        if (!buffer.hasRemaining()) {
+            //Yep...so refill the buffer
+            if (timedRead() <= 0)
+                return -1;
+        }
+
+        return (int) (buffer.get() & 0xff);
+    }
+
+    public long readLong() throws IOException {
+        //Have we read everything?
+        if (!buffer.hasRemaining()) {
+            //Yep...so refill the buffer
+            if (timedRead() <= 0)
+                return -1;
+        }
+
+        if (buffer.remaining() >= 8){
+           return buffer.getLong();
+        } else {
+            throw new BufferUnderflowException();
+        }
+    }
+
+    public int readInt() throws IOException {
+        //Have we read everything?
+        if (!buffer.hasRemaining()) {
+            //Yep...so refill the buffer
+            if (timedRead() <= 0)
+                return -1;
+        }
+
+        if (buffer.remaining() >= 4){
+            return buffer.getInt();
+        } else {
+            throw new BufferUnderflowException();
+        }
+    }
+
+    public int read(byte[] bytes) throws IOException {
+        return this.read(bytes, 0, bytes.length);
+    }
+
+    public int read(byte[] bytes, int offset, int len) throws IOException {
+        //Have we read everything?
+        if (!buffer.hasRemaining()) {
+            //Yep...so refill the buffer
+            if (timedRead() <= 0)
+                return -1;
+        }
+
+        if (len > buffer.remaining()) {
+            len = buffer.remaining();
+        }
+        buffer.get(bytes, offset, len);
+
+        return (len);
+
+    }
+
+    private int timedRead() throws IOException {
+        //Reset the buffer
+        buffer.clear();
+        int read = internalRead();
+
+        //Test if anything came inbound...
+        if (read == 0) {
+            //Nope...now need to wait
+            Selector selector = null;
+            SelectionKey key = null;
+            try{
+                Selector.open();
+
+                //Listen in for data on the line
+                channel.register(selector, SelectionKey.OP_READ);
+
+                int retVal = selector.select(timeout);
+                if (retVal == 0) {
+                    //Hmmm...wakeup or timeout and nothing found?
+                    return 0;
+                }
+
+                //retVal must equal 1, because there is only 1 key, so read it
+                read = internalRead();
+            }finally{
+                if (key != null){
+                    key.cancel();
+                }
+                if (selector != null){
+                    selector.close();
+                }
+            }
+        }
+
+        buffer.flip();
+        return read;
+    }
+
+    private int internalRead() throws IOException {
+
+        int read = 0;
+        int totalBytes = 0;
+
+        do {
+            read = channel.read(buffer);
+            totalBytes += read;
+        } while (read > 0);
+
+        //Test for a closed socket
+        if (read < 0) {
+            //Return with EOF
+            return -1;
+        }
+
+        return totalBytes;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelInputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.gcache.util;
+
+import java.nio.channels.SocketChannel;
+import java.nio.channels.Selector;
+import java.nio.channels.SelectionKey;
+import java.nio.ByteBuffer;
+import java.io.IOException;
+
+public class BufferChannelReader {
+    private SocketChannel channel = null;
+    private ByteBuffer buffer = null;
+    private long timeout = 10000;
+
+    public BufferChannelReader(SocketChannel channel, ByteBuffer buffer) {
+        this.channel = channel;
+        this.buffer = buffer;
+        buffer.flip();
+    }
+
+    public void reset(SocketChannel channel, ByteBuffer buffer) {
+        this.channel = channel;
+        this.buffer = buffer;
+        buffer.flip();
+    }
+
+    public int readBuffer(int expectedCount) throws IOException {
+        int read = timedRead(expectedCount);
+
+        return read;
+    }
+
+    private int timedRead(int size) throws IOException {
+        //Reset the buffer
+        buffer.clear();
+        int read = internalRead();
+
+        //If we got the full tomato, then leave
+        if (read == size)
+            return read;
+
+        //Test if anything came inbound or we have more bytes that need reading...
+        if ((read == 0) || (read < size)) {
+
+            //Nope...now need to wait
+            Selector selector = null;
+            SelectionKey key = null;
+            try {
+                Selector.open();
+
+                //Listen in for data on the line
+                channel.register(selector, SelectionKey.OP_READ);
+
+                int retVal = selector.select(timeout);
+                if (retVal == 0) {
+                    //Hmmm...wakeup or timeout and nothing found?
+                    return 0;
+                }
+
+                //retVal must equal 1, because there is only 1 key, so read it
+                int moreRead = internalRead();
+                //Error?
+                if (moreRead < 0)
+                    return moreRead;
+
+                read += moreRead;
+
+            } finally {
+                if (key != null) {
+                    key.cancel();
+                }
+                if (selector != null) {
+                    selector.close();
+                }
+            }
+        }
+
+        return read;
+    }
+
+    private int internalRead() throws IOException {
+
+        int read = 0;
+        int totalBytes = 0;
+
+        do {
+            read = channel.read(buffer);
+            totalBytes += read;
+        } while (read > 0);
+
+        //Test for a closed socket
+        if (read < 0) {
+            //Return with EOF
+            return -1;
+        }
+
+        return totalBytes;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelReader.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java Thu Nov  9 10:23:28 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.util;
+
+import java.nio.channels.SocketChannel;
+import java.nio.channels.Selector;
+import java.nio.channels.SelectionKey;
+import java.nio.ByteBuffer;
+import java.io.IOException;
+
+public class BufferChannelWriter {
+
+    private SocketChannel channel = null;
+    private ByteBuffer buffer = null;
+    private long timeout = 10000;
+
+    public BufferChannelWriter(SocketChannel channel, ByteBuffer buffer) {
+        this.channel = channel;
+        this.buffer = buffer;
+    }
+
+    public int writeBuffer(int expectedCount) throws IOException {
+        int read = timedWrite(expectedCount);
+
+        return read;
+    }
+
+    private int timedWrite(int size) throws IOException {
+        int written = internalWrite();
+
+        //If we got the full tomato, then leave
+        if (written == size)
+            return written;
+
+        //Test if anything came inbound or we have more bytes that need reading...
+        if ((written == 0) || (written < size)) {
+
+            //Nope...now need to wait
+            Selector selector = null;
+            SelectionKey key = null;
+            try {
+                Selector.open();
+
+                //Listen in for data on the line
+                channel.register(selector, SelectionKey.OP_WRITE);
+
+                int retVal = selector.select(timeout);
+                if (retVal == 0) {
+                    //Hmmm...wakeup or timeout and nothing found?
+                    return 0;
+                }
+
+                //retVal must equal 1, because there is only 1 key, so read it
+                int moreWritten = internalWrite();
+                //Error?
+                if (moreWritten < 0)
+                    return moreWritten;
+
+                written += moreWritten;
+
+            } finally {
+                if (key != null) {
+                    key.cancel();
+                }
+                if (selector != null) {
+                    selector.close();
+                }
+            }
+        }
+
+        return written;
+    }
+
+    private int internalWrite() throws IOException {
+
+        int written = 0;
+        int totalBytes = 0;
+
+        do {
+            written = channel.write(buffer);
+            totalBytes += written;
+        } while (written > 0);
+
+        //Test for a closed socket
+        if (written < 0) {
+            //Return with EOF
+            return -1;
+        }
+
+        return totalBytes;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/BufferChannelWriter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,111 @@
+/*
+ * 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.util;
+
+public class ByteArray {
+
+    private byte[] array;
+    private int offset;
+    private int length;
+    private int hash = 0;
+
+    /**
+     * Create an instance of this class that wraps ths given array.
+     * This class does not make a copy of the array, it just saves
+     * the reference.
+     */
+    public ByteArray(byte[] array, int offset, int length) {
+        this.array = array;
+        this.offset = offset;
+        this.length = length;
+    }
+
+    public ByteArray(byte[] array) {
+        this(array, 0, array.length);
+    }
+
+    public ByteArray() {
+    }
+
+    public void setBytes(byte[] array) {
+        this.array = array;
+        offset = 0;
+        length = array.length;
+        hash = 0;
+    }
+
+    public void setBytes(byte[] array, int length) {
+        this.array = array;
+        this.offset = 0;
+        this.length = length;
+        this.hash = 0;
+    }
+
+    public byte[] getBytes(){
+       return array; 
+    }
+
+    public void setBytes(byte[] array, int offset, int length) {
+        this.array = array;
+        this.offset = offset;
+        this.length = length;
+        this.hash = 0;
+    }
+
+    public boolean equals(Object other) {
+        if (other instanceof ByteArray) {
+            ByteArray ob = (ByteArray) other;
+            return ByteArray.equals(array, offset, length, ob.array, ob.offset, ob.length);
+        }
+        return false;
+    }
+
+    public int hashCode() {
+
+        if (array == null){
+            return 0;
+        }
+
+        if (this.hash != 0){
+            return this.hash;
+        }
+
+        int hash = length;
+        for (int i = 0; i < length; i++) {
+            hash = hash * 31 + array[i];
+        }
+
+        this.hash = hash;
+
+        return hash;
+    }
+
+    private static boolean equals(byte[] a, int aOffset, int aLength, byte[] b, int bOffset, int bLength) {
+
+        if (aLength != bLength)
+            return false;
+
+        for (int i = 0; i < aLength; i++) {
+            if (a[i + aOffset] != b[i + bOffset])
+                return false;
+        }
+        return true;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArray.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,96 @@
+/*
+ * 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.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ByteArrayInputStream extends InputStream {
+    byte buffer[];
+    int limit;
+    int pos;
+    int mark;
+
+    public ByteArrayInputStream(byte data[]) {
+        this(data, 0, data.length);
+    }
+
+    public ByteArrayInputStream(ByteSequence sequence) {
+        this(sequence.getData(), sequence.getOffset(), sequence.getLength());
+    }
+
+    public ByteArrayInputStream(byte data[], int offset, int size) {
+        this.buffer = data;
+        this.mark= this.pos = offset;
+        this.limit = offset+size;
+    }
+
+    public int read() throws IOException {
+        if( pos < limit )
+            return buffer[pos++] & 0xff;
+        else
+            return -1;
+    }
+
+    public int read(byte[] b) throws IOException {
+        return read(b, 0, b.length);
+    }
+
+    public int read(byte b[], int off, int len) {
+        if (pos < limit) {
+            len = Math.min(len, limit-pos);
+            if (len > 0) {
+                System.arraycopy(buffer, pos, b, off, len);
+                pos += len;
+            }
+            return len;
+        } else {
+            return -1;
+        }
+    }
+
+    public long skip(long len) throws IOException {
+        if (pos < limit) {
+            len = Math.min(len, limit-pos);
+            if (len > 0) {
+                pos += len;
+            }
+            return len;
+        } else {
+            return -1;
+        }
+    }
+
+    public int available() {
+        return limit - pos;
+    }
+
+    public boolean markSupported() {
+        return true;
+    }
+
+    public void mark(int markpos) {
+        mark = pos;
+    }
+
+    public void reset() {
+        pos = mark;
+    }
+
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayInputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java Thu Nov  9 10:23:28 2006
@@ -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.util;
+
+import java.io.OutputStream;
+
+/**
+ * Very similar to the java.io.ByteArrayOutputStream but this version
+ * is not thread safe and the resulting data is returned in a ByteSequence
+ * to avoid an extra byte[] allocation.
+ */
+public class ByteArrayOutputStream extends OutputStream {
+
+    byte buffer[];
+    int size;
+
+    public ByteArrayOutputStream() {
+        this(512);
+    }
+
+    public ByteArrayOutputStream(int capacity) {
+        buffer = new byte[capacity];
+    }
+
+    public void write(int b) {
+        int newsize = size + 1;
+        checkCapacity(newsize);
+        buffer[size] = (byte) b;
+        size = newsize;
+    }
+
+    public void write(byte b[], int off, int len) {
+        int newsize = size + len;
+        checkCapacity(newsize);
+        System.arraycopy(b, off, buffer, size, len);
+        size = newsize;
+    }
+
+    /**
+     * Ensures the the buffer has at least the minimumCapacity specified.
+     *
+     * @param minimumCapacity
+     */
+    private void checkCapacity(int minimumCapacity) {
+        if (minimumCapacity > buffer.length) {
+            byte b[] = new byte[Math.max(buffer.length << 1, minimumCapacity)];
+            System.arraycopy(buffer, 0, b, 0, size);
+            buffer = b;
+        }
+    }
+
+    public void reset() {
+        size = 0;
+    }
+
+    public ByteSequence toByteSequence() {
+        return new ByteSequence(buffer, 0, size);
+    }
+
+    public byte[] toByteArray() {
+        byte rc[] = new byte[size];
+        System.arraycopy(buffer, 0, rc, 0, size);
+        return rc;
+    }
+
+    public int size() {
+        return size;
+    }
+}
+

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteArrayOutputStream.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.util;
+
+public class ByteSequence {
+    public byte[] data;
+    public int offset;
+    public int length;
+
+    public ByteSequence(byte data[]) {
+        this.data = data;
+        this.offset = 0;
+        this.length = data.length;
+    }
+
+    public ByteSequence(byte data[], int offset, int length) {
+        this.data = data;
+        this.offset = offset;
+        this.length = length;
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    public int getOffset() {
+        return offset;
+    }
+
+    public void setData(byte[] data) {
+        this.data = data;
+    }
+
+    public void setLength(int length) {
+        this.length = length;
+    }
+
+    public void setOffset(int offset) {
+        this.offset = offset;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/ByteSequence.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,140 @@
+/**
+ *
+ * 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.util;
+
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+
+public class CipherUtil {
+    private static final byte[] _3desData = { (byte) 0x76, (byte) 0x6F,
+	    (byte) 0xBA, (byte) 0x39, (byte) 0x31, (byte) 0x2F, (byte) 0x0D,
+	    (byte) 0x4A, (byte) 0xA3, (byte) 0x90, (byte) 0x55, (byte) 0xFE,
+	    (byte) 0x55, (byte) 0x65, (byte) 0x61, (byte) 0x13, (byte) 0x34,
+	    (byte) 0x82, (byte) 0x12, (byte) 0x17, (byte) 0xAC, (byte) 0x77,
+	    (byte) 0x39, (byte) 0x19 };
+
+    private static SecretKeySpec _key = new SecretKeySpec(_3desData, "DESede");
+    private static PrivateKey privateKey = null;
+    public static PublicKey publicKey = null;
+
+    static {
+	KeyPairGenerator keyGen;
+	try {
+	    keyGen = KeyPairGenerator.getInstance("RSA");
+	    keyGen.initialize(1024);
+	    KeyPair keypair = keyGen.genKeyPair();
+	    privateKey = keypair.getPrivate();
+	    publicKey = keypair.getPublic();
+	} catch (NoSuchAlgorithmException e) {
+	    throw new RuntimeException(e);
+	}
+    }
+    
+    public static PublicKey bytesToPublicKey(byte rawKey[]) throws InvalidKeySpecException{
+	X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(rawKey);
+	try {
+	    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+	    PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
+	    
+	    return pubKey;
+	} catch (NoSuchAlgorithmException e) {
+	    throw new RuntimeException(e);
+	}
+    }
+    
+    public static byte[] RSAEncrypt(String text, PublicKey key) {
+	byte[] plaintext = text.getBytes();
+
+	try {
+	    // Get a RSA Cipher object
+	    Cipher cipher = Cipher.getInstance("RSA"); 
+	    
+	    // Set it into encryption mode
+	    cipher.init(Cipher.ENCRYPT_MODE, key);
+
+	    // Encrypt data
+	    return cipher.doFinal(plaintext);
+
+	} catch (Exception e) {
+	    throw new RuntimeException(e);
+	}
+    }
+    
+    public static String RSADecrypt(byte[] cipherText) throws InvalidKeyException {
+
+	try {
+
+	    Cipher cipher = Cipher.getInstance("RSA"); // Triple-DES encryption
+	    cipher.init(Cipher.DECRYPT_MODE, privateKey);
+
+	    // Decrypt data
+	    String plainText = new String(cipher.doFinal(cipherText));
+
+	    return plainText;
+
+	} catch (Exception e) {
+	    throw new InvalidKeyException(e.getMessage());
+	}
+    }
+    
+    public static byte[] TripleDESencrypt(String text) {
+	byte[] plaintext = text.getBytes();
+
+	try {
+	    // Get a 3DES Cipher object
+	    Cipher cipher = Cipher.getInstance("DESede"); // Triple-DES encryption
+	    // Set it into encryption mode
+	    cipher.init(Cipher.ENCRYPT_MODE, _key);
+
+	    // Encrypt data
+	    return cipher.doFinal(plaintext);
+
+	} catch (Exception e) {
+	    throw new RuntimeException(e);
+	}
+    }
+
+    public static String TripleDESdecrypt(byte[] cipherText) throws InvalidKeyException {
+
+	try {
+
+	    // Get a 3DES Cipher object
+	    Cipher cipher = Cipher.getInstance("DESede"); // Triple-DES encryption
+	    // Set it into decryption mode
+	    cipher.init(Cipher.DECRYPT_MODE, _key);
+
+	    // Decrypt data
+	    String plainText = new String(cipher.doFinal(cipherText));
+
+	    return plainText;
+
+	} catch (Exception e) {
+	    throw new InvalidKeyException(e.getMessage());
+	}
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/CipherUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,104 @@
+/**
+ *
+ * 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.util;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+public class FactoryFinder {
+    private final String path;
+    private final ConcurrentHashMap classMap = new ConcurrentHashMap();
+
+    public FactoryFinder(String path) {
+        this.path = path;
+    }
+
+    /**
+     * Creates a new instance of the given key
+     *
+     * @param key is the key to add to the path to find a text file
+     *            containing the factory name
+     * @return a newly created instance
+     */
+    public Object newInstance(String key)
+            throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException
+    {
+        return newInstance(key, null);
+    }
+
+    public Object newInstance(String key, String propertyPrefix)
+            throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException
+    {
+        if (propertyPrefix == null)
+            propertyPrefix = "";
+
+        Class clazz = (Class) classMap.get(propertyPrefix + key);
+        if (clazz == null) {
+            clazz = newInstance(doFindFactoryProperies(key), propertyPrefix);
+            classMap.put(propertyPrefix + key, clazz);
+        }
+        return clazz.newInstance();
+    }
+
+    private Class newInstance(Properties properties, String propertyPrefix) throws ClassNotFoundException, IOException {
+
+        String className = properties.getProperty(propertyPrefix + "class");
+        if (className == null) {
+            throw new IOException("Expected property is missing: " + propertyPrefix + "class");
+        }
+        Class clazz;
+        try {
+            clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
+        } catch (ClassNotFoundException e) {
+            clazz = FactoryFinder.class.getClassLoader().loadClass(className);
+        }
+
+        return clazz;
+    }
+
+    private Properties doFindFactoryProperies(String key) throws IOException {
+        String uri = path + key;
+
+        // lets try the thread context class loader first
+        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri);
+        if (in == null) {
+            in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri);
+            if (in == null) {
+                throw new IOException("Could not find factory class for resource: " + uri);
+            }
+        }
+
+        // lets load the file
+        BufferedInputStream reader = null;
+        try {
+            reader = new BufferedInputStream(in);
+            Properties properties = new Properties();
+            properties.load(reader);
+            return properties;
+        } finally {
+            try {
+                reader.close();
+            } catch (Exception e) {
+            }
+        }
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/FactoryFinder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java Thu Nov  9 10:23:28 2006
@@ -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.util;
+
+public class HexDump {
+    
+    public static String hexString(byte[] b) {
+	StringBuffer sb = new StringBuffer();
+        sb.append("\n");
+        for (int i = 0; i < b.length; ++i) {
+            if (i % 16 == 0) {
+                sb.append(Integer.toHexString ((i & 0xFFFF) | 0x10000).substring(1,5) + " - ");
+            }
+            sb.append(Integer.toHexString((b[i]&0xFF) | 0x100).substring(1,3) + " ");
+            if (i % 16 == 15 || i == b.length - 1)
+            {
+                int j;
+                for (j = 16 - i % 16; j > 1; --j)
+                    sb.append("   ");
+                sb.append(" - ");
+                int start = (i / 16) * 16;
+                int end = (b.length < i + 1) ? b.length : (i + 1);
+                for (j = start; j < end; ++j)
+                    if (b[j] >= 32 && b[j] <= 126)
+                        sb.append((char)b[j]);
+                    else
+                        sb.append(".");
+                sb.append("\n");
+            }
+        }
+        return 	sb.toString();
+    }
+    
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/HexDump.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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

Added: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java?view=auto&rev=473002
==============================================================================
--- geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java (added)
+++ geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java Thu Nov  9 10:23:28 2006
@@ -0,0 +1,46 @@
+/**
+ *
+ * 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.util;
+
+import java.io.IOException;
+
+public final class IOExceptionSupport {
+    public static IOException create(String msg, Throwable cause) {
+        IOException exception = new IOException(msg);
+        exception.initCause(cause);
+        return exception;
+    }
+
+    public static IOException create(String msg, Exception cause) {
+        IOException exception = new IOException(msg);
+        exception.initCause(cause);
+        return exception;
+    }
+
+    public static IOException create(Throwable cause) {
+        IOException exception = new IOException(cause.getMessage());
+        exception.initCause(cause);
+        return exception;
+    }
+
+    public static IOException create(Exception cause) {
+        IOException exception = new IOException(cause.getMessage());
+        exception.initCause(cause);
+        return exception;
+    }
+}

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gcache/common/src/main/java/org/apache/geronimo/gcache/util/IOExceptionSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

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