jakarta-jcs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asm...@apache.org
Subject svn commit: r280251 [1/2] - in /jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary: javagroups/ lateral/ lateral/javagroups/ lateral/javagroups/behavior/ lateral/javagroups/utils/
Date Mon, 12 Sep 2005 04:26:59 GMT
Author: asmuts
Date: Sun Sep 11 21:26:41 2005
New Revision: 280251

URL: http://svn.apache.org/viewcvs?rev=280251&view=rev
Log:
Refactoring lateral manager and factory.  The old model was to have one factory
and mananger know about all types of lateral.  This created too many dependencies 
and forced lots of ad hoc logic into the managers.  The new model will have
each lateral responsible for its own factory and manager.  This keeps things clean
and will allow laterals to ahve their own configuration settings.  The old
attributes object had stuff for every lateral, but only a small subset applied
to any given lateral.  This is a work in progress but it is almost done.  

The new cache.ccf config for laterals will not be backward compatible, but the 
changes will be minor.  When it is done the version will be 1.3.  After more 
testing, this will be the release candidate major version.

I'm moving the javagroups stuff into to jdk1.4 specific jar.  

The refactoring should be done in a few days.  This will allow us to release a 1.3 core library
and a 1.4 extension jar.  

Added:
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCache.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheAttributes.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheFactory.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/JGConnectionHolder.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralCacheJGListener.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralGroupCacheJGListener.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheFactory.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheManager.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiver.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiverConnection.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGSender.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGService.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/IJGConstants.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/ILateralCacheJGListener.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGRpcOpener.java
    jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGSocketOpener.java

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCache.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCache.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCache.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,450 @@
+package org.apache.jcs.auxiliary.javagroups;
+
+/* 
+ * Copyright 2001-2004 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.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.Vector;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.engine.CacheConstants;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheType;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.control.CompositeCache;
+import org.apache.jcs.engine.stats.StatElement;
+import org.apache.jcs.engine.stats.Stats;
+import org.apache.jcs.engine.stats.behavior.IStatElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
+import org.jgroups.Address;
+import org.jgroups.Channel;
+import org.jgroups.MembershipListener;
+import org.jgroups.Message;
+import org.jgroups.View;
+import org.jgroups.blocks.GroupRequest;
+import org.jgroups.blocks.MessageDispatcher;
+import org.jgroups.blocks.RequestHandler;
+import org.jgroups.util.RspList; 
+
+/**
+ * Auxiliary cache using javagroups. Expects to be created with a Channel, the
+ * {@link JavaGroupsCacheFactory}is responsible for creating that channel. To
+ * do so it uses configuration properties specified by an instance of
+ * {@link JavaGroupsCacheAttributes}.
+ * <p>
+ * At creation time the provided channel is connected to a group having the same
+ * name as the cache / region name this auxiliary is associated with. update /
+ * remove / removeAll operations are broadcast to all members of the group. A
+ * listener thread processes requests from other members of the group, and
+ * dispatches to appropriate methods on the associated CompositeCache.
+ * </p>
+ * <p>
+ * Calls to get are currently ignored.
+ * <p>
+ * Messages are sent to peers asynchronously. Synchronous messaging could be
+ * added using MessageDispatcher or RpcDispatcher. Combined with a get
+ * implementation this could provide much higher cache consistency (but with a
+ * substantial speed penalty).
+ * 
+ * @version $Id: JavaGroupsCache.java 264665 2005-08-30 01:10:34Z asmuts $
+ */
+public class JavaGroupsCache
+    implements AuxiliaryCache, RequestHandler, MembershipListener
+{
+    private final Log log = LogFactory.getLog( JavaGroupsCache.class );
+
+    private String cacheName;
+
+    private int status;
+
+    private boolean getFromPeers;
+
+    private ICompositeCacheManager cacheMgr;
+
+    private Channel channel;
+
+    private MessageDispatcher dispatcher;
+
+    public JavaGroupsCache( ICompositeCacheManager cache, String cacheName, Channel channel, boolean getFromPeers )
+        throws Exception
+    {
+        this.cacheMgr = cacheMgr;
+
+        this.cacheName = cacheName;
+        this.channel = channel;
+
+        this.getFromPeers = getFromPeers;
+
+        // The adapter listens to the channel and fires MessageListener events
+        // on this object.
+
+        dispatcher = new MessageDispatcher( channel, null, this, this );
+
+        // Connect channel to the 'group' for our region name
+
+        channel.setOpt( Channel.LOCAL, Boolean.FALSE );
+
+        channel.connect( cacheName );
+
+        // If all the above succeed, the cache is now alive.
+
+        this.status = CacheConstants.STATUS_ALIVE;
+
+        log.info( "Initialized for cache: " + cacheName );
+    }
+
+    public void send( ICacheElement element, int command )
+    {
+        Request request = new Request( element, command );
+
+        try
+        {
+            dispatcher.castMessage( null, new Message( null, null, request ), GroupRequest.GET_NONE, 0 );
+
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed to send JavaGroups message", e );
+        }
+    }
+
+    // ----------------------------------------------- interface AuxiliaryCache
+
+    /**
+     * Sends the provided element to all peers (connected to the same channel
+     * and region name).
+     * 
+     * @param ce
+     *            CacheElement to replicate
+     * @throws IOException
+     *             Never thrown by this implementation
+     */
+    public void update( ICacheElement ce )
+        throws IOException
+    {
+        send( ce, Request.UPDATE );
+    }
+
+    /**
+     * If 'getFromPeers' is true, this will attempt to get the requested element
+     * from ant other members of the group.
+     * 
+     * @param key
+     * @return
+     * @throws IOException
+     *             Never thrown by this implementation
+     */
+    public ICacheElement get( Serializable key )
+        throws IOException
+    {
+        if ( getFromPeers )
+        {
+            CacheElement element = new CacheElement( cacheName, key, null );
+
+            Request request = new Request( element, Request.GET );
+
+            // Cast message and wait for all responses.
+
+            // FIXME: we can stop waiting after the first not null response,
+            //        that is more difficult to implement however.
+
+            RspList responses = dispatcher.castMessage( null, new Message( null, null, request ), GroupRequest.GET_ALL,
+                                                        0 );
+
+            // Get results only gives the responses which were not null
+
+            Vector results = responses.getResults();
+
+            // If there were any non null results, return the first
+
+            if ( results.size() > 0 )
+            {
+                return (ICacheElement) results.get( 0 );
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Sends a request to all peers to remove the element having the provided
+     * key.
+     * 
+     * @param key
+     *            Key of element to be removed
+     * @throws IOException
+     *             Never thrown by this implementation
+     */
+    public boolean remove( Serializable key )
+        throws IOException
+    {
+        CacheElement ce = new CacheElement( cacheName, key, null );
+
+        send( ce, Request.REMOVE );
+
+        return false;
+    }
+
+    /**
+     * Sends a request to remove ALL elements from the peers
+     * 
+     * @throws IOException
+     *             Never thrown by this implementation
+     */
+    public void removeAll()
+        throws IOException
+    {
+        CacheElement ce = new CacheElement( cacheName, null, null );
+
+        send( ce, Request.REMOVE_ALL );
+    }
+
+    /**
+     * Dispose this cache, terminates the listener thread and disconnects the
+     * channel from the group.
+     * 
+     * @throws IOException
+     */
+    public void dispose()
+        throws IOException
+    {
+        // This will join the scheduler thread and ensure everything terminates
+
+        dispatcher.stop();
+
+        // Now we can disconnect from the group and close the channel
+
+        channel.disconnect();
+        channel.close();
+
+        status = CacheConstants.STATUS_DISPOSED;
+
+        log.info( "Disposed for cache: " + cacheName );
+    }
+
+    /**
+     * Since this is a lateral, size is not defined.
+     * 
+     * @return Always returns 0
+     */
+    public int getSize()
+    {
+        return 0;
+    }
+
+    /**
+     * Returns the status of this auxiliary.
+     * 
+     * @return One of the status constants from {@link CacheConstants}
+     */
+    public int getStatus()
+    {
+        return status;
+    }
+
+    /**
+     * Accessor for cacheName property
+     * 
+     * @return Name of cache / region this auxiliary is associated with.
+     */
+    public String getCacheName()
+    {
+        return cacheName;
+    }
+
+    /**
+     * Not implemented (I believe since get is not supported, this should also
+     * not be).
+     * 
+     * @param group
+     *            Ignored
+     * @return Always reurns null
+     */
+    public Set getGroupKeys( String group )
+    {
+        return null;
+    }
+
+    // --------------------------------------------------- interface ICacheType
+
+    /**
+     * Get the cache type (always Lateral).
+     * 
+     * @return Always returns ICacheType.LATERAL_CACHE
+     */
+    public int getCacheType()
+    {
+        return ICacheType.LATERAL_CACHE;
+    }
+
+    // ----------------------------------------------- interface RequestHandler
+
+    /**
+     * Handles a message from a peer. The message should contain a Request, and
+     * depending on the command this will call localUpdate, localRemove, or
+     * localRemoveAll on the associated CompositeCache.
+     * 
+     * @param msg
+     *            The JavaGroups Message
+     * @return Always returns null
+     */
+    public Object handle( Message msg )
+    {
+        try
+        {
+            Request request = (Request) msg.getObject();
+
+            // Switch based on the command and invoke the
+            // appropriate method on the associate composite cache
+
+            switch ( request.getCommand() )
+            {
+                case Request.GET:
+
+                    return getCompositeCache().localGet( request.getCacheElement().getKey() );
+                // break;
+
+                case Request.UPDATE:
+
+                    getCompositeCache().localUpdate( request.getCacheElement() );
+                    break;
+
+                case Request.REMOVE:
+
+                    getCompositeCache().localRemove( request.getCacheElement().getKey() );
+                    break;
+
+                case Request.REMOVE_ALL:
+
+                    getCompositeCache().localRemoveAll();
+                    break;
+
+                default:
+
+                    log.error( "Recieved unknown command" );
+            }
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed to process received JavaGroups message", e );
+        }
+
+        return null;
+    }
+
+    /**
+     * TODO speed this up. We don't want to ahve to go through the manager
+     * everytime.
+     * 
+     * @return ICompositeCache
+     */
+    private CompositeCache getCompositeCache()
+    {
+        return cacheMgr.getCache( this.cacheName );
+    }
+
+    // ------------------------------------------- interface MembershipListener
+
+    public void viewAccepted( View view )
+    {
+        log.info( "View Changed: " + String.valueOf( view ) );
+    }
+
+    public void suspect( Address suspectedAddress )
+    {
+    }
+
+    public void block()
+    {
+    }
+
+    /**
+     * getStats
+     * 
+     * @return String
+     */
+    public String getStats()
+    {
+        return getStatistics().toString();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
+     */
+    public IStats getStatistics()
+    {
+        IStats stats = new Stats();
+        stats.setTypeName( "JavaGroups Cache" );
+
+        ArrayList elems = new ArrayList();
+
+        IStatElement se = null;
+
+        // no data gathered here
+
+        // get an array and put them in the Stats object
+        IStatElement[] ses = (IStatElement[]) elems.toArray( new StatElement[0] );
+        stats.setStatElements( ses );
+
+        return stats;
+    }
+
+    // ---------------------------------------------------------- inner classes
+
+    /**
+     * Object for messages, wraps the command type (update, remove, or remove
+     * all) and original cache element to distribute.
+     */
+    static class Request
+        implements Serializable
+    {
+        public final static int UPDATE = 1;
+
+        public final static int REMOVE = 2;
+
+        public final static int REMOVE_ALL = 3;
+
+        public final static int GET = 5;
+
+        private ICacheElement cacheElement;
+
+        private int command;
+
+        public Request( ICacheElement cacheElement, int command )
+        {
+            this.cacheElement = cacheElement;
+            this.command = command;
+        }
+
+        public ICacheElement getCacheElement()
+        {
+            return cacheElement;
+        }
+
+        public int getCommand()
+        {
+            return command;
+        }
+    }
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheAttributes.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheAttributes.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheAttributes.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheAttributes.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,107 @@
+package org.apache.jcs.auxiliary.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import org.apache.jcs.auxiliary.AbstractAuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+
+/**
+ * Attributes used by {@link JavaGroupsCacheFactory#createCache}to configure an
+ * instance of {@link JavaGroupsCache}.
+ * 
+ * <h3>Configurable Properties:</h3>
+ * 
+ * <dl>
+ * <dt>channelFactoryClassName</dt>
+ * <dd>Name of an {@link org.jgroups.ChannelFactory}implementation which will
+ * be used to create the channel for the instance. Defaults to
+ * {@link org.jgroups.JChannelFactory}.</dd>
+ * <dt>channelProperties</dt>
+ * <dd>A JavaGroups properties object which will be used by the channel to
+ * create the protocol stack. Either a properties string, or the URL of a file
+ * containing the properties in XML form is valid. Defaults to null which causes
+ * the Channel implementation to use its defaults.</dd>
+ * </dl>
+ * 
+ * @version $Id: JavaGroupsCacheAttributes.java,v 1.2 2005/01/07 22:27:54 asmuts
+ *          Exp $
+ */
+public class JavaGroupsCacheAttributes
+    extends AbstractAuxiliaryCacheAttributes
+    implements AuxiliaryCacheAttributes
+{
+    private String channelFactoryClassName = "org.jgroups.JChannelFactory";
+
+    private String channelProperties = null;
+
+    private boolean getFromPeers = false;
+
+    public String getChannelFactoryClassName()
+    {
+        return channelFactoryClassName;
+    }
+
+    public void setChannelFactoryClassName( String channelFactoryClassName )
+    {
+        this.channelFactoryClassName = channelFactoryClassName;
+    }
+
+    public String getJGChannelProperties()
+    {
+        return channelProperties;
+    }
+
+    public void setChannelProperties( String channelProperties )
+    {
+        this.channelProperties = channelProperties;
+    }
+
+    public boolean isGetFromPeers()
+    {
+        return getFromPeers;
+    }
+
+    public void setGetFromPeers( boolean getFromPeers )
+    {
+        this.getFromPeers = getFromPeers;
+    }
+
+    /**
+     * Return a copy of this JavaGroupsCacheAttributes, cast to an
+     * AuxiliaryCacheAttributes
+     */
+    public AuxiliaryCacheAttributes copy()
+    {
+        return (AuxiliaryCacheAttributes) this.clone();
+    }
+
+    /**
+     * Return a clone of this JavaGroupsCacheAttributes
+     */
+    public Object clone()
+    {
+        JavaGroupsCacheAttributes copy = new JavaGroupsCacheAttributes();
+
+        copy.cacheName = this.cacheName;
+        copy.name = this.name;
+
+        copy.channelFactoryClassName = this.channelFactoryClassName;
+        copy.channelProperties = this.channelProperties;
+
+        return copy;
+    }
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheFactory.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheFactory.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/JavaGroupsCacheFactory.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,97 @@
+package org.apache.jcs.auxiliary.javagroups;
+ 
+/* 
+ * Copyright 2001-2004 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.
+ */
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.jgroups.Channel;
+import org.jgroups.ChannelFactory;
+
+/**
+ * AuxiliaryCacheFactory for creating instances of {@link JavaGroupsCache}for a
+ * particular CompositeCache and {@link JavaGroupsCacheAttributes}.
+ * 
+ * @version $Id: JavaGroupsCacheFactory.java,v 1.2 2004/06/12 02:34:13 asmuts
+ *          Exp $
+ */
+public class JavaGroupsCacheFactory
+    implements AuxiliaryCacheFactory
+{
+    private final static Log log = LogFactory.getLog( JavaGroupsCacheFactory.class );
+
+    private String name;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
+     *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr )
+    {
+        // ignore the maanger
+
+        try
+        {
+            // Cast provided attributes to JavaGroupsCacheAttributes
+
+            JavaGroupsCacheAttributes attributes = (JavaGroupsCacheAttributes) iaca;
+
+            // Create a ChannelFactory using the classname specified in the
+            // config as 'channelFactoryClassName'
+
+            ChannelFactory factory = (ChannelFactory) Class.forName( attributes.getChannelFactoryClassName() )
+                .newInstance();
+
+            // Create a channel based on 'channelProperties' from the config
+
+            Channel channel = factory.createChannel( attributes.getJGChannelProperties() );
+
+            // Return a new JavaGroupsCache for the new channel.
+
+            return new JavaGroupsCache( cacheMgr, attributes.getCacheName(), channel, attributes.isGetFromPeers() );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed to create JavaGroupsCache", e );
+
+            return null;
+        }
+    }
+
+    /**
+     * Accessor for name property
+     * @return String
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * Mutator for name property
+     * @param name
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheFactory.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,270 @@
+package org.apache.jcs.auxiliary.lateral;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.javagroups.LateralCacheJGListener;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPListener;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.discovery.UDPDiscoveryManager;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.discovery.UDPDiscoveryService;
+import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * Constructs a LateralCacheNoWaitFacade for the given configuration. Each
+ * lateral service / local relationship is managed by one manager. This manager
+ * canl have multiple caches. The remote relationships are consolidated and
+ * restored via these managers. The facade provides a front to the composite
+ * cache so the implmenetation is transparent.
+ *  
+ * @deprecated use the new TYPE specific lateral factories.
+ */
+public class LateralCacheFactory
+    extends LateralCacheAbstractFactory
+{
+    private final static Log log = LogFactory.getLog( LateralCacheFactory.class );
+
+    private String name;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
+     *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr )
+    {
+
+        LateralCacheAttributes lac = (LateralCacheAttributes) iaca;
+        ArrayList noWaits = new ArrayList();
+
+        if ( lac.getTransmissionType() == LateralCacheAttributes.UDP )
+        {
+            LateralCacheManager lcm = LateralCacheManager.getInstance( lac, cacheMgr );
+            ICache ic = lcm.getCache( lac.getCacheName() );
+            if ( ic != null )
+            {
+                noWaits.add( ic );
+            }
+        }
+        else if ( lac.getTransmissionType() == LateralCacheAttributes.JAVAGROUPS )
+        {
+            LateralCacheManager lcm = LateralCacheManager.getInstance( lac, cacheMgr );
+            ICache ic = lcm.getCache( lac.getCacheName() );
+            if ( ic != null )
+            {
+                noWaits.add( ic );
+            }
+        }
+
+        // for each server listed get the manager for that server.
+        // from that manager get the cache for this region name.
+        else if ( lac.getTransmissionType() == LateralCacheAttributes.TCP )
+        {
+
+            //pars up the tcp servers and set the tcpServer value and
+            // get the manager and then get the cache
+            StringTokenizer it = new StringTokenizer( lac.tcpServers, "," );
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Configured for " + it.countTokens() + "  servers." );
+            }
+            while ( it.hasMoreElements() )
+            {
+                String server = (String) it.nextElement();
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "tcp server = " + server );
+                }
+                LateralCacheAttributes lacC = (LateralCacheAttributes) lac.copy();
+                lacC.setTcpServer( server );
+                LateralCacheManager lcm = LateralCacheManager.getInstance( lacC, cacheMgr );
+                ICache ic = lcm.getCache( lacC.getCacheName() );
+                if ( ic != null )
+                {
+                    noWaits.add( ic );
+                }
+                else
+                {
+                    log.debug( "noWait is null, no lateral connection made" );
+                }
+            }
+        }
+        else if ( lac.getTransmissionType() == LateralCacheAttributes.XMLRPC )
+        {
+
+            //pars up the tcp servers and set the tcpServer value and
+            // get the manager and then get the cache
+            //Iterator it = lac.tcpServers.iterator();
+            //while( it.hasNext() ) {
+
+            StringTokenizer it = new StringTokenizer( lac.getHttpServers(), "," );
+            while ( it.hasMoreElements() )
+            {
+                //String server = (String)it.next();
+                String server = (String) it.nextElement();
+                //p( "tcp server = " + server );
+                lac.setHttpServer( server );
+                LateralCacheManager lcm = LateralCacheManager.getInstance( lac, cacheMgr );
+                ICache ic = lcm.getCache( lac.getCacheName() );
+                if ( ic != null )
+                {
+                    noWaits.add( ic );
+                }
+                else
+                {
+                    log.warn( "noWait is null" );
+                }
+            }
+
+        }
+        else if ( lac.getTransmissionType() == LateralCacheAttributes.HTTP )
+        {
+            StringTokenizer it = new StringTokenizer( lac.getHttpServers(), "," );
+            while ( it.hasMoreElements() )
+            {
+                String server = (String) it.nextElement();
+                lac.setHttpServer( server );
+                LateralCacheManager lcm = LateralCacheManager.getInstance( lac, cacheMgr );
+                ICache ic = lcm.getCache( lac.getCacheName() );
+                if ( ic != null )
+                {
+                    noWaits.add( ic );
+                }
+            }
+        }
+
+        createListener( lac, cacheMgr );
+
+        // create the no wait facade.
+        LateralCacheNoWaitFacade lcnwf = new LateralCacheNoWaitFacade( (LateralCacheNoWait[]) noWaits
+            .toArray( new LateralCacheNoWait[0] ), iaca.getCacheName() );
+
+        createDiscoveryService( lac, lcnwf, cacheMgr );
+
+        return lcnwf;
+    }
+
+    /*
+     *  (non-Javadoc)
+     * @see org.apache.jcs.auxiliary.lateral.LateralCacheAbstractFactory#createListener(org.apache.jcs.auxiliary.lateral.LateralCacheAttributes, org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public void createListener( LateralCacheAttributes lac, ICompositeCacheManager cacheMgr )
+    {
+        // don't create a listener if we are not receiving.
+        if ( lac.isReceive() )
+        {
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Creating listener for " + lac );
+            }
+
+            try
+            {
+                if ( lac.getTransmissionType() == ILateralCacheAttributes.TCP )
+                {
+                    // make a listener. if one doesn't exist
+                    LateralTCPListener.getInstance( lac, cacheMgr );
+                }
+                else if ( lac.getTransmissionType() == ILateralCacheAttributes.JAVAGROUPS )
+                {
+                    LateralCacheJGListener.getInstance( lac, cacheMgr );
+                }
+
+            }
+            catch ( Exception e )
+            {
+                log.error( "Problem creating lateral listener", e );
+            }
+        }
+        else
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Not creating a listener since we are not receiving." );
+            }
+        }
+    }
+
+    /**
+     * Creates the discovery service. Only creates this for tcp laterals right
+     * now.
+     * 
+     * @param lac
+     * @param lcnwf
+     * @param cacheMgr
+     * @return null if none is created.
+     */
+    private UDPDiscoveryService createDiscoveryService( LateralCacheAttributes lac, LateralCacheNoWaitFacade lcnwf,
+                                                       ICompositeCacheManager cacheMgr )
+    {
+        UDPDiscoveryService discovery = null;
+
+        //      create the UDP discovery for the TCP lateral
+        if ( lac.isUdpDiscoveryEnabled() )
+        {
+            if ( lac.getTransmissionType() != LateralCacheAttributes.TCP )
+            {
+                log
+                    .warn( "UdpDiscoveryEnabled is set to true, but the Lateral cache type is not TCP.  Discovery will not be enabled." );
+            }
+            else
+            {
+                // need a factory for this so it doesn't
+                // get dereferenced, also we don't want one for every region.
+                discovery = UDPDiscoveryManager.getInstance().getService( lac, cacheMgr );
+
+                discovery.addNoWaitFacade( lcnwf, lac.getCacheName() );
+
+                if ( log.isInfoEnabled() )
+                {
+                    log.info( "Created UDPDiscoveryService for TCP lateral cache." );
+                }
+            }
+        }
+        return discovery;
+    }
+
+    /**
+     * Gets the name attribute of the LateralCacheFactory object
+     * 
+     * @return The name value
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * Sets the name attribute of the LateralCacheFactory object
+     * 
+     * @param name
+     *            The new name value
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/LateralCacheManager.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,374 @@
+package org.apache.jcs.auxiliary.lateral;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheObserver;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
+import org.apache.jcs.auxiliary.lateral.javagroups.LateralCacheJGListener;
+import org.apache.jcs.auxiliary.lateral.javagroups.LateralJGService;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPListener;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPService;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * Creates lateral caches. Lateral caches are primarily used for removing non
+ * laterally configured caches. Non laterally configured cache regions should
+ * still bea ble to participate in removal. But if there is a non laterally
+ * configured cache hub, then lateral removals may be necessary. For flat
+ * webserver production environments, without a strong machine at the app server
+ * level, distribution and search may need to occur at the lateral cache level.
+ * This is currently not implemented in the lateral cache.
+ * <p>
+ * 
+ * @TODO: - need freeCache, release, getStats - need to find an interface
+ *        acceptible for all - cache managers or a manager within a type
+ * 
+ * @deprecated use individual cache managers
+ */
+public class LateralCacheManager
+    implements ILateralCacheManager
+{
+    private final static Log log = LogFactory.getLog( LateralCacheManager.class );
+
+    private static LateralCacheMonitor monitor;
+
+    final static Map instances = new HashMap();
+
+    // each manager instance has caches
+    final Map caches = new HashMap();
+
+    /**
+     * Description of the Field
+     */
+    protected ILateralCacheAttributes lca;
+
+    private int clients;
+
+    /**
+     * Handle to the lateral cache service; or a zombie handle if failed to
+     * connect.
+     */
+    private ILateralCacheService lateralService;
+
+    /**
+     * Wrapper of the lateral cache watch service; or wrapper of a zombie
+     * service if failed to connect.
+     */
+    private LateralCacheWatchRepairable lateralWatch;
+
+    private ICompositeCacheManager cacheMgr;
+
+    /**
+     * Returns an instance of the LateralCacheManager.
+     * 
+     * @param lca
+     * @param cacheMgr
+     *            this allows the auxiliary to be passed a cache manager.
+     * @return
+     */
+    public static LateralCacheManager getInstance( ILateralCacheAttributes lca, ICompositeCacheManager cacheMgr )
+    {
+        LateralCacheManager ins = (LateralCacheManager) instances.get( lca.toString() );
+        synchronized ( instances )
+        {
+            if ( ins == null )
+            {
+                log.info( "Instance for [" + lca.toString() + "] is null, creating" );
+
+                ins = (LateralCacheManager) instances.get( lca.toString() );
+                if ( ins == null )
+                {
+                    ins = new LateralCacheManager( lca, cacheMgr );
+                    instances.put( lca.toString(), ins );
+                }
+            }
+        }
+
+        ins.clients++;
+        // Fires up the monitoring daemon.
+        if ( monitor == null )
+        {
+            monitor = new LateralCacheMonitor( ins );
+            // Should never be null
+            if ( monitor != null )
+            {
+                Thread t = new Thread( monitor );
+                t.setDaemon( true );
+                t.start();
+            }
+        }
+        return ins;
+    }
+
+    /**
+     * Constructor for the LateralCacheManager object
+     * 
+     * @param lcaA
+     * @param cacheMgr
+     */
+    private LateralCacheManager( ILateralCacheAttributes lcaA, ICompositeCacheManager cacheMgr )
+    {
+        this.lca = lcaA;
+
+        this.cacheMgr = cacheMgr;
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Creating lateral cache service, lca = " + this.lca );
+        }
+
+        // need to create the service based on the type
+
+        try
+        {
+            if ( this.lca.getTransmissionType() == ILateralCacheAttributes.TCP )
+            {
+                log.debug( "Creating TCP service" );
+                log.info( "Creating TCP service, lca = " + this.lca );
+
+                this.lateralService = new LateralTCPService( this.lca );
+            }
+            else if ( this.lca.getTransmissionType() == ILateralCacheAttributes.JAVAGROUPS )
+            {
+                log.debug( "Creating JAVAGROUPS service" );
+
+                this.lateralService = new LateralJGService( this.lca );
+            }
+
+            else
+            {
+                log.error( "Type not recognized, must zombie" );
+
+                throw new Exception( "no known transmission type for lateral cache." );
+            }
+
+            if ( this.lateralService == null )
+            {
+                log.error( "No service created, must zombie" );
+
+                throw new Exception( "No service created for lateral cache." );
+            }
+
+            this.lateralWatch = new LateralCacheWatchRepairable();
+            this.lateralWatch.setCacheWatch( new ZombieLateralCacheWatch() );
+
+        }
+        catch ( Exception ex )
+        {
+            // Failed to connect to the lateral server.
+            // Configure this LateralCacheManager instance to use the
+            // "zombie" services.
+
+            log.error( "Failure, lateral instance will use zombie service", ex );
+
+            this.lateralService = new ZombieLateralCacheService();
+            this.lateralWatch = new LateralCacheWatchRepairable();
+            this.lateralWatch.setCacheWatch( new ZombieLateralCacheWatch() );
+
+            // Notify the cache monitor about the error, and kick off
+            // the recovery process.
+            monitor.notifyError();
+        }
+    }
+
+    /**
+     * Adds the lateral cache listener to the underlying cache-watch service.
+     * 
+     * @param cacheName
+     *            The feature to be added to the LateralCacheListener attribute
+     * @param listener
+     *            The feature to be added to the LateralCacheListener attribute
+     * @exception IOException
+     */
+    public void addLateralCacheListener( String cacheName, ILateralCacheListener listener )
+        throws IOException
+    {
+        synchronized ( this.caches )
+        {
+            this.lateralWatch.addCacheListener( cacheName, listener );
+        }
+    }
+
+    /**
+     * Called to access a precreated region or construct one with defaults.
+     * Since all aux cache access goes through the manager, this will never be
+     * called.
+     * <p>
+     * After getting the manager instance for a server, the factory gets a cache
+     * for the region name it is constructing.
+     * <p>
+     * There should be one manager per server and one cache per region per
+     * manager.
+     * 
+     * @return AuxiliaryCache
+     * @param cacheName
+     */
+    public AuxiliaryCache getCache( String cacheName )
+    {
+        LateralCacheNoWait c = null;
+        synchronized ( this.caches )
+        {
+            c = (LateralCacheNoWait) this.caches.get( cacheName );
+            if ( c == null )
+            {
+                LateralCacheAttributes attr = (LateralCacheAttributes) lca.copy();
+                attr.setCacheName( cacheName );
+                LateralCache cache = new LateralCache( attr, this.lateralService, monitor );
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "Created cache for noWait, cache = [" + cache + "]" );
+                }
+                c = new LateralCacheNoWait( cache );
+                this.caches.put( cacheName, c );
+
+                log.info( "Created LateralCacheNoWait for " + this.lca + " LateralCacheNoWait = [" + c + "]" );
+            }
+        }
+
+        // don't create a listener if we are not receiving.
+        if ( lca.isReceive() )
+        {
+            try
+            {
+                if ( this.lca.getTransmissionType() == ILateralCacheAttributes.TCP )
+                {
+                    addLateralCacheListener( cacheName, LateralTCPListener.getInstance( this.lca, cacheMgr ) );
+                }
+                else if ( this.lca.getTransmissionType() == ILateralCacheAttributes.JAVAGROUPS )
+                {
+                    addLateralCacheListener( cacheName, LateralCacheJGListener.getInstance( this.lca, cacheMgr ) );
+                }
+            }
+            catch ( IOException ioe )
+            {
+                log.error( "Problem creating lateral listener", ioe );
+            }
+            catch ( Exception e )
+            {
+                log.error( "Problem creating lateral listener", e );
+            }
+        }
+        else
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Not creating a listener since we are not receiving." );
+            }
+        }
+
+        // TODO: need listener repair
+
+        return c;
+    }
+
+    /**
+     * Gets the cacheType attribute of the LateralCacheManager object
+     * 
+     * @return The cache type value
+     */
+    public int getCacheType()
+    {
+        return LATERAL_CACHE;
+    }
+
+    /**
+     * Gets the stats attribute of the LateralCacheManager object
+     * 
+     * @return String
+     */
+    public String getStats()
+    {
+        // add something here
+        return "";
+    }
+
+    /**
+     * Fixes up all the caches managed by this cache manager.
+     * 
+     * @param lateralService
+     * @param lateralWatch
+     */
+    public void fixCaches( ILateralCacheService lateralService, ILateralCacheObserver lateralWatch )
+    {
+        log.debug( "Fixing lateral caches:" );
+
+        synchronized ( this.caches )
+        {
+            this.lateralService = lateralService;
+            // need to implment an observer for some types of laterals( http and
+            // tcp)
+            //this.lateralWatch.setCacheWatch(lateralWatch);
+            for ( Iterator en = this.caches.values().iterator(); en.hasNext(); )
+            {
+                LateralCacheNoWait cache = (LateralCacheNoWait) en.next();
+                cache.fixCache( this.lateralService );
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#getInstances()
+     */
+    public Map getInstances()
+    {
+        return instances;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#getCaches()
+     */
+    public Map getCaches()
+    {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#fixService()
+     */
+    public Object fixService()
+        throws IOException
+    {
+        Object service = null;
+        try
+        {
+            if ( lca.getTransmissionType() == lca.TCP )
+            {
+                service = new LateralTCPService( lca );                
+            }
+        }
+        catch ( Exception ex )
+        {
+            log.error( "Can't fix " + ex.getMessage() );
+            throw new IOException( "Can't fix " + ex.getMessage() );
+        }
+        return service;
+    }
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/JGConnectionHolder.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/JGConnectionHolder.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/JGConnectionHolder.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/JGConnectionHolder.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,155 @@
+package org.apache.jcs.auxiliary.lateral.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.javagroups.behavior.IJGConstants;
+import org.apache.jcs.auxiliary.lateral.javagroups.behavior.ILateralCacheJGListener;
+import org.apache.jcs.auxiliary.lateral.javagroups.utils.JGRpcOpener;
+import org.apache.jcs.auxiliary.lateral.javagroups.utils.JGSocketOpener;
+import org.jgroups.Channel;
+import org.jgroups.blocks.RpcDispatcher;
+
+/**
+ * This holds connections, or channels, for jgroups.
+ */
+public class JGConnectionHolder
+{
+
+    private final static Log log = LogFactory.getLog( JGConnectionHolder.class );
+
+    private Channel jg;
+
+    private RpcDispatcher disp;
+
+    private ILateralCacheAttributes ilca;
+
+    /**
+     * Description of the Field
+     */
+    protected final static HashMap instances = new HashMap();
+
+    /**
+     * Gets the instance attribute of the LateralGroupCacheJGListener class
+     * 
+     * @return The instance value
+     * @param ilca
+     */
+    public static JGConnectionHolder getInstance( ILateralCacheAttributes ilca )
+    {
+        //throws IOException, NotBoundException
+        //JGConnectionHolder ins = (JGConnectionHolder) instances.get( ilca.getJGChannelProperties() );
+        JGConnectionHolder ins = (JGConnectionHolder) instances.get( ilca.getCacheName() );
+        try
+        {
+            synchronized ( JGConnectionHolder.class )
+            {
+                if ( ins == null )
+                {
+                    ins = new JGConnectionHolder( ilca );
+                }
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "created new listener " + ilca.getJGChannelProperties() );
+                }
+                instances.put( ilca.getJGChannelProperties(), ins );
+            }
+        }
+        catch ( Exception e )
+        {
+            log.error( "trouble intializing", e );
+        }
+        return ins;
+    }
+
+    /**
+     * Constructor for the JGConnectionHolder object
+     * 
+     * @param lca
+     * @param ilca
+     */
+    private JGConnectionHolder( ILateralCacheAttributes ilca )
+    {
+        this.ilca = ilca;
+    }
+
+    /**
+     * Creates a channel.
+     * 
+     * @return channel
+     * @exception IOException
+     */
+    public synchronized Channel getChannel()
+        throws IOException
+    {
+        if ( jg == null )
+        {
+            //jg = JGSocketOpener.openSocket( ilca, 5000, IJGConstants.DEFAULT_JG_GROUP_NAME );
+            jg = JGSocketOpener.openSocket( ilca, 5000, this.ilca.getCacheName() );
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Created channel " + jg + " for region name " + this.ilca.getCacheName() );
+                if ( jg != null )
+                {
+                    log.info( "Channel connection status; Connected = " + jg.isConnected() + " Open = " + jg.isOpen() );                    
+                }
+            }
+        }
+        return jg;
+    }
+
+    /**
+     * Gets the Dispatcher attribute of the JGConnectionHolder object
+     * 
+     * @return The Dispatcher value
+     * @exception IOException
+     */
+    public synchronized RpcDispatcher getDispatcher()
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Creating Dispatcher, jgroups group name " + IJGConstants.RPC_JG_GROUP_NAME );
+        }
+
+        try
+        {
+            if ( disp == null )
+            {
+                synchronized ( JGConnectionHolder.class )
+                {
+                    if ( disp == null )
+                    {
+                        disp = JGRpcOpener.openSocket( (ILateralCacheJGListener) LateralGroupCacheJGListener
+                            .getInstance( ilca ), ilca, 5000, IJGConstants.RPC_JG_GROUP_NAME );
+                    }
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            log.error( "Problem creating dispatcher", e );
+        }
+        return disp;
+    }
+
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralCacheJGListener.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralCacheJGListener.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralCacheJGListener.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralCacheJGListener.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,305 @@
+package org.apache.jcs.auxiliary.lateral.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.lateral.LateralCacheInfo;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
+import org.apache.jcs.auxiliary.lateral.javagroups.behavior.ILateralCacheJGListener;
+import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.control.CompositeCache;
+import org.apache.jcs.engine.control.CompositeCacheManager;
+
+/**
+ * JavaGroups listener. Good for distributing cache data accross multiple vms on
+ * the same machine. You also don't need to know the number of listerners for
+ * configuration.
+ *  
+ */
+public class LateralCacheJGListener
+    implements ILateralCacheJGListener, Serializable
+{
+    private final static Log log = LogFactory.getLog( LateralCacheJGListener.class );
+
+    /**
+     * Description of the Field
+     */
+    protected transient ICompositeCacheManager cacheMgr;
+
+    /**
+     * Description of the Field
+     */
+    protected final static HashMap instances = new HashMap();
+
+    // instance vars
+    private LateralJGReceiver receiver;
+
+    private ILateralCacheAttributes ilca;
+
+    private int puts = 0;
+
+    /**
+     * Only need one since it does work for all regions, just reference by
+     * multiple region names.
+     * 
+     * @param ilca
+     */
+    protected LateralCacheJGListener( ILateralCacheAttributes ilca )
+    {
+        this.ilca = ilca;
+    }
+
+    /**
+     * Description of the Method
+     */
+    public void init()
+    {
+        try
+        {
+            // need to connect based on type
+            //ILateralCacheListener ilcl = this;
+            receiver = new LateralJGReceiver( ilca, this );
+            Thread t = new Thread( receiver );
+            t.start();
+        }
+        catch ( Exception ex )
+        {
+            log.error( ex );
+            throw new IllegalStateException( ex.getMessage() );
+        }
+    }
+
+    /**
+     * let the lateral cache set a listener_id. Since there is only one
+     * listerenr for all the regions and every region gets registered? the id
+     * shouldn't be set if it isn't zero. If it is we assume that it is a
+     * reconnect.
+     * 
+     * @param id
+     *            The new listenerId value
+     * @exception IOException
+     */
+    public void setListenerId( long id )
+        throws IOException
+    {
+        LateralCacheInfo.listenerId = id;
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "set listenerId = " + id );
+        }
+    }
+
+    /**
+     * Gets the listenerId attribute of the LateralCacheJGListener object
+     * 
+     * @return The listenerId value
+     * @exception IOException
+     */
+    public long getListenerId()
+        throws IOException
+    {
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "get listenerId = " + LateralCacheInfo.listenerId );
+        }
+        return LateralCacheInfo.listenerId;
+    }
+
+    /**
+     * Gets the instance attribute of the LateralCacheJGListener class
+     * 
+     * @return The instance value
+     * @param ilca
+     * @param cacheMgr
+     */
+    public static ILateralCacheListener getInstance( ILateralCacheAttributes ilca, ICompositeCacheManager cacheMgr )
+    {
+
+        //throws IOException, NotBoundException
+        ILateralCacheListener ins = (ILateralCacheListener) instances.get( ilca.getJGChannelProperties() );
+
+        synchronized ( LateralCacheJGListener.class )
+        {
+            if ( ins == null )
+            {
+                ins = new LateralCacheJGListener( ilca );
+
+                ins.setCacheManager( cacheMgr );
+
+                ins.init();
+            }
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "created new listener " + ilca.getJGChannelProperties() );
+            }
+            instances.put( ilca.getJGChannelProperties(), ins );
+        }
+
+        return ins;
+    }
+
+    //////////////////////////// implements the ILateralCacheListener
+    // interface. //////////////
+    /**
+     * @param element
+     * @param cb
+     * @exception IOException
+     */
+    public void handlePut( ICacheElement element )
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "PUTTING ELEMENT FROM LATERAL" );
+        }
+
+        puts++;
+        if ( log.isInfoEnabled() )
+        {
+            if ( puts % 100 == 0 )
+            {
+                log.info( "puts = " + puts );
+            }
+        }
+
+        getCache( element.getCacheName() ).localUpdate( element );
+
+    }
+
+    /**
+     * Description of the Method
+     * 
+     * @param cacheName
+     * @param key
+     * @exception IOException
+     */
+    public void handleRemove( String cacheName, Serializable key )
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "handleRemove> cacheName=" + cacheName + ", key=" + key );
+        }
+
+        getCache( cacheName ).localRemove( key );
+    }
+
+    /**
+     * Description of the Method
+     * 
+     * @param cacheName
+     * @exception IOException
+     */
+    public void handleRemoveAll( String cacheName )
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "handleRemoveAll> cacheName=" + cacheName );
+        }
+
+        ICache cache = getCache( cacheName );
+        cache.removeAll();
+    }
+
+    /**
+     * Test get implementation.
+     * 
+     * @return
+     * @param cacheName
+     * @param key
+     * @exception IOException
+     */
+    public Serializable handleGet( String cacheName, Serializable key )
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "handleGet> cacheName=" + cacheName + ", key = " + key );
+        }
+
+        return getCache( cacheName ).localGet( key );
+    }
+
+    /**
+     * Description of the Method
+     * 
+     * @param cacheName
+     * @exception IOException
+     */
+    public void handleDispose( String cacheName )
+        throws IOException
+    {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "handleDispose> cacheName=" + cacheName );
+        }
+        // TODO handle active disposal
+        //this.getCacheManager().freeCache( cacheName, true );
+    }
+
+    /**
+     * Gets the cacheManager attribute of the LateralCacheTCPListener object
+     * 
+     * @param name
+     * @return CompositeCache
+     */
+    protected CompositeCache getCache( String name )
+    {
+        if ( cacheMgr == null )
+        {
+            cacheMgr = CompositeCacheManager.getInstance();
+
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "cacheMgr = " + cacheMgr );
+            }
+        }
+
+        return cacheMgr.getCache( name );
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener#setCacheManager(org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public void setCacheManager( ICompositeCacheManager cacheMgr )
+    {
+        this.cacheMgr = cacheMgr;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener#getCacheManager()
+     */
+    public ICompositeCacheManager getCacheManager()
+    {
+        return this.cacheMgr;
+    }
+
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralGroupCacheJGListener.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralGroupCacheJGListener.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralGroupCacheJGListener.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralGroupCacheJGListener.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,108 @@
+package org.apache.jcs.auxiliary.lateral.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
+import org.apache.jcs.auxiliary.lateral.javagroups.behavior.ILateralCacheJGListener;
+
+import org.apache.jcs.engine.control.CompositeCacheManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Id: LateralGroupCacheJGListener.java,v 1.6 2002/02/15 04:33:37
+ *          jtaylor Exp $
+ */
+public class LateralGroupCacheJGListener
+    extends LateralCacheJGListener
+    implements ILateralCacheJGListener
+{
+    private final static Log log = LogFactory.getLog( LateralGroupCacheJGListener.class );
+
+    /**
+     * Constructor for the LateralGroupCacheJGListener object
+     * 
+     * @param ilca
+     */
+    protected LateralGroupCacheJGListener( ILateralCacheAttributes ilca )
+    {
+        super( ilca );
+        log.debug( "creating LateralGroupCacheJGListener" );
+    }
+
+    /**
+     * Gets the instance attribute of the LateralGroupCacheJGListener class
+     * @param ilca
+     * 
+     * @return The instance value
+     */
+    public static ILateralCacheListener getInstance( ILateralCacheAttributes ilca )
+    {
+        //throws IOException, NotBoundException
+        ILateralCacheListener ins = (ILateralCacheListener) instances
+            .get( String.valueOf( ilca.getUdpMulticastAddr() ) );
+        synchronized ( LateralGroupCacheJGListener.class )
+        {
+            if ( ins == null )
+            {
+                ins = new LateralGroupCacheJGListener( ilca );
+                ins.init();
+            }
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "created new listener " + ilca.getUdpMulticastAddr() );
+            }
+            instances.put( String.valueOf( ilca.getUdpMulticastAddr() ), ins );
+        }
+
+        return ins;
+    }
+
+    // override for new funcitonality
+    // lazy init is too slow, find a better way
+    /**
+     * Gets the cacheManager attribute of the LateralGroupCacheJGListener object
+     */
+    protected void ensureCacheManager()
+    {
+        try
+        {
+            if ( cacheMgr == null )
+            {
+                cacheMgr = CompositeCacheManager.getInstance();
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( " groupcache cacheMgr = " + cacheMgr );
+                }
+            }
+            else
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "already got groupcache cacheMgr = " + cacheMgr );
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            log.error( e );
+        }
+    }
+
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheFactory.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheFactory.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheFactory.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,111 @@
+package org.apache.jcs.auxiliary.lateral.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.LateralCacheAbstractFactory;
+import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.LateralCacheNoWait;
+import org.apache.jcs.auxiliary.lateral.LateralCacheNoWaitFacade;
+import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * Constructs a LateralCacheNoWaitFacade for the given configuration. Each
+ * lateral service / local relationship is managed by one manager. This manager
+ * canl have multiple caches. The remote relationships are consolidated and
+ * restored via these managers. The facade provides a front to the composite
+ * cache so the implmenetation is transparent.
+ * 
+ * @deprecated use the new TYPE specific lateral factories.
+ */
+public class LateralJGCacheFactory
+    extends LateralCacheAbstractFactory
+{
+    private final static Log log = LogFactory.getLog( LateralJGCacheFactory.class );
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.AuxiliaryCacheFactory#createCache(org.apache.jcs.auxiliary.AuxiliaryCacheAttributes,
+     *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr )
+    {
+
+        LateralCacheAttributes lac = (LateralCacheAttributes) iaca;
+        ArrayList noWaits = new ArrayList();
+
+        LateralJGCacheManager lcm = LateralJGCacheManager.getInstance( lac, cacheMgr );
+        ICache ic = lcm.getCache( lac.getCacheName() );
+        if ( ic != null )
+        {
+            noWaits.add( ic );
+        }
+
+        createListener( lac, cacheMgr );
+
+        // create the no wait facade.
+        LateralCacheNoWaitFacade lcnwf = new LateralCacheNoWaitFacade( (LateralCacheNoWait[]) noWaits
+            .toArray( new LateralCacheNoWait[0] ), iaca.getCacheName() );
+
+        return lcnwf;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.lateral.LateralCacheAbstractFactory#createListener(org.apache.jcs.auxiliary.lateral.LateralCacheAttributes,
+     *      org.apache.jcs.engine.behavior.ICompositeCacheManager)
+     */
+    public void createListener( LateralCacheAttributes lac, ICompositeCacheManager cacheMgr )
+    {
+        // don't create a listener if we are not receiving.
+        if ( lac.isReceive() )
+        {
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Creating listener for " + lac );
+            }
+
+            try
+            {
+
+                LateralCacheJGListener.getInstance( lac, cacheMgr );
+
+            }
+            catch ( Exception e )
+            {
+                log.error( "Problem creating lateral listener", e );
+            }
+        }
+        else
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Not creating a listener since we are not receiving." );
+            }
+        }
+    }
+
+}

Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheManager.java?rev=280251&view=auto
==============================================================================
--- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheManager.java (added)
+++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGCacheManager.java Sun Sep 11 21:26:41 2005
@@ -0,0 +1,334 @@
+package org.apache.jcs.auxiliary.lateral.javagroups;
+
+/*
+ * Copyright 2001-2004 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.
+ */
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.lateral.LateralCache;
+import org.apache.jcs.auxiliary.lateral.LateralCacheAbstractManager;
+import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.LateralCacheMonitor;
+import org.apache.jcs.auxiliary.lateral.LateralCacheNoWait;
+import org.apache.jcs.auxiliary.lateral.LateralCacheWatchRepairable;
+import org.apache.jcs.auxiliary.lateral.ZombieLateralCacheService;
+import org.apache.jcs.auxiliary.lateral.ZombieLateralCacheWatch;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager;
+import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
+import org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPService;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * Creates lateral caches. Lateral caches are primarily used for removing non
+ * laterally configured caches. Non laterally configured cache regions should
+ * still bea ble to participate in removal. But if there is a non laterally
+ * configured cache hub, then lateral removals may be necessary. For flat
+ * webserver production environments, without a strong machine at the app server
+ * level, distribution and search may need to occur at the lateral cache level.
+ * This is currently not implemented in the lateral cache.
+ * <p>
+ * 
+ * @TODO: - need freeCache, release, getStats - need to find an interface
+ *        acceptible for all - cache managers or a manager within a type
+ * 
+ * @deprecated use individual cache managers
+ */
+public class LateralJGCacheManager
+    extends LateralCacheAbstractManager
+{
+    private final static Log log = LogFactory.getLog( LateralJGCacheManager.class );
+
+    private static LateralCacheMonitor monitor;
+
+    final static Map instances = new HashMap();
+
+    // each manager instance has caches
+    final Map caches = new HashMap();
+
+    /**
+     * Description of the Field
+     */
+    protected ILateralCacheAttributes lca;
+
+    private int clients;
+
+    /**
+     * Handle to the lateral cache service; or a zombie handle if failed to
+     * connect.
+     */
+    private ILateralCacheService lateralService;
+
+    /**
+     * Wrapper of the lateral cache watch service; or wrapper of a zombie
+     * service if failed to connect.
+     */
+    private LateralCacheWatchRepairable lateralWatch;
+
+    private ICompositeCacheManager cacheMgr;
+
+    /**
+     * Returns an instance of the LateralCacheManager.
+     * 
+     * @param lca
+     * @param cacheMgr
+     *            this allows the auxiliary to be passed a cache manager.
+     * @return
+     */
+    public static LateralJGCacheManager getInstance( ILateralCacheAttributes lca, ICompositeCacheManager cacheMgr )
+    {
+        LateralJGCacheManager ins = (LateralJGCacheManager) instances.get( lca.toString() );
+        synchronized ( instances )
+        {
+            if ( ins == null )
+            {
+                log.info( "Instance for [" + lca.toString() + "] is null, creating" );
+
+                ins = (LateralJGCacheManager) instances.get( lca.toString() );
+                if ( ins == null )
+                {
+                    ins = new LateralJGCacheManager( lca, cacheMgr );
+                    instances.put( lca.toString(), ins );
+                }
+            }
+        }
+
+        
+        createMonitor( ins );
+        
+        return ins;
+    }
+
+    
+    /**
+     * The monitor needs reference to one instance, acutally just a type.
+     * 
+     * refactor this.
+     * 
+     * @param instance
+     */
+    private static synchronized void createMonitor( ILateralCacheManager instance )
+    {
+//      only want one monitor per lateral type
+        // Fires up the monitoring daemon.
+        if ( monitor == null )
+        {
+            monitor = new LateralCacheMonitor( instance );
+            // Should never be null
+            if ( monitor != null )
+            {
+                Thread t = new Thread( monitor );
+                t.setDaemon( true );
+                t.start();
+            }
+        }
+
+    }
+    
+    /**
+     * Constructor for the LateralCacheManager object
+     * 
+     * @param lcaA
+     * @param cacheMgr
+     */
+    private LateralJGCacheManager( ILateralCacheAttributes lcaA, ICompositeCacheManager cacheMgr )
+    {
+        this.lca = lcaA;
+
+        this.cacheMgr = cacheMgr;
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Creating lateral cache service, lca = " + this.lca );
+        }
+
+        // need to create the service based on the type
+
+        try
+        {
+            if ( this.lca.getTransmissionType() == ILateralCacheAttributes.TCP )
+            {
+                log.debug( "Creating TCP service" );
+                log.info( "Creating TCP service, lca = " + this.lca );
+
+                this.lateralService = new LateralTCPService( this.lca );
+            }
+            else if ( this.lca.getTransmissionType() == ILateralCacheAttributes.JAVAGROUPS )
+            {
+                log.debug( "Creating JAVAGROUPS service" );
+
+                this.lateralService = new LateralJGService( this.lca );
+            }
+
+            else
+            {
+                log.error( "Type not recognized, must zombie" );
+
+                throw new Exception( "no known transmission type for lateral cache." );
+            }
+
+            if ( this.lateralService == null )
+            {
+                log.error( "No service created, must zombie" );
+
+                throw new Exception( "No service created for lateral cache." );
+            }
+
+            this.lateralWatch = new LateralCacheWatchRepairable();
+            this.lateralWatch.setCacheWatch( new ZombieLateralCacheWatch() );
+
+        }
+        catch ( Exception ex )
+        {
+            // Failed to connect to the lateral server.
+            // Configure this LateralCacheManager instance to use the
+            // "zombie" services.
+
+            log.error( "Failure, lateral instance will use zombie service", ex );
+
+            this.lateralService = new ZombieLateralCacheService();
+            this.lateralWatch = new LateralCacheWatchRepairable();
+            this.lateralWatch.setCacheWatch( new ZombieLateralCacheWatch() );
+
+            // Notify the cache monitor about the error, and kick off
+            // the recovery process.
+            
+            createMonitor( this );
+            monitor.notifyError();
+        }
+    }
+
+    /**
+     * Adds the lateral cache listener to the underlying cache-watch service.
+     * 
+     * @param cacheName
+     *            The feature to be added to the LateralCacheListener attribute
+     * @param listener
+     *            The feature to be added to the LateralCacheListener attribute
+     * @exception IOException
+     */
+    public void addLateralCacheListener( String cacheName, ILateralCacheListener listener )
+        throws IOException
+    {
+        synchronized ( this.caches )
+        {
+            this.lateralWatch.addCacheListener( cacheName, listener );
+        }
+    }
+
+    /**
+     * Called to access a precreated region or construct one with defaults.
+     * Since all aux cache access goes through the manager, this will never be
+     * called.
+     * <p>
+     * After getting the manager instance for a server, the factory gets a cache
+     * for the region name it is constructing.
+     * <p>
+     * There should be one manager per server and one cache per region per
+     * manager.
+     * 
+     * @return AuxiliaryCache
+     * @param cacheName
+     */
+    public AuxiliaryCache getCache( String cacheName )
+    {
+        LateralCacheNoWait c = null;
+        synchronized ( this.caches )
+        {
+            c = (LateralCacheNoWait) this.caches.get( cacheName );
+            if ( c == null )
+            {
+                LateralCacheAttributes attr = (LateralCacheAttributes) lca.copy();
+                attr.setCacheName( cacheName );
+                LateralCache cache = new LateralCache( attr, this.lateralService, monitor );
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( "Created cache for noWait, cache = [" + cache + "]" );
+                }
+                c = new LateralCacheNoWait( cache );
+                this.caches.put( cacheName, c );
+
+                log.info( "Created LateralCacheNoWait for " + this.lca + " LateralCacheNoWait = [" + c + "]" );
+            }
+        }
+
+        // don't create a listener if we are not receiving.
+        if ( lca.isReceive() )
+        {
+            try
+            {
+
+                addLateralCacheListener( cacheName, LateralCacheJGListener.getInstance( this.lca, cacheMgr ) );
+
+            }
+            catch ( IOException ioe )
+            {
+                log.error( "Problem creating lateral listener", ioe );
+            }
+            catch ( Exception e )
+            {
+                log.error( "Problem creating lateral listener", e );
+            }
+        }
+        else
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Not creating a listener since we are not receiving." );
+            }
+        }
+
+        // TODO: need listener repair
+
+        return c;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#getInstances()
+     */
+    public Map getInstances()
+    {
+        return instances;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#fixService()
+     */
+    public Object fixService()
+        throws IOException
+    {
+        Object service = null;
+        try
+        {
+            // TODO, do we need to do something here?
+        }
+        catch ( Exception ex )
+        {
+            log.error( "Can't fix " + ex.getMessage() );
+            throw new IOException( "Can't fix " + ex.getMessage() );
+        }
+        return service;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org


Mime
View raw message