Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiver.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiver.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiver.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiver.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,158 @@ +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 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.jgroups.Channel; +import org.jgroups.ChannelNotConnectedException; +import org.jgroups.Message; +import org.jgroups.blocks.RpcDispatcher; + +/** + * Processes commands from the server socket. + * + * @version $Id: LateralJGReceiver.java 224346 2005-06-04 02:01:59Z asmuts $ + */ +public class LateralJGReceiver + implements IJGConstants, Runnable +{ + private final static Log log = LogFactory.getLog( LateralJGReceiver.class ); + + private ILateralCacheJGListener ilcl; + + private ILateralCacheAttributes ilca; + + /** + * Main processing method for the LateralJGReceiver object + */ + public void run() + { + try + { + if ( log.isDebugEnabled() ) + { + log.debug( "Listening" ); + } + + JGConnectionHolder holder = JGConnectionHolder.getInstance( ilca ); + Channel javagroups = holder.getChannel(); + + // don't need a dispatcher unless we are allowing gets. + // gets are not supported right now. + if ( !ilca.getPutOnlyMode() ) + { + RpcDispatcher disp = holder.getDispatcher(); + if ( log.isDebugEnabled() ) + { + log.debug( "Dispatcher = " + disp ); + } + } + + if ( javagroups == null ) + { + log.error( "JavaGroups is null" ); + throw new IOException( "javagroups is null" ); + } + + int conProbCnt = 0; + while ( true ) + { + if ( log.isDebugEnabled() ) + { + log.debug( "Wating for messages." ); + } + + Message mes = null; + try + { + Object obj = javagroups.receive( 0 ); + if ( obj != null && obj instanceof org.jgroups.Message ) + { + mes = (Message) obj; + if ( log.isDebugEnabled() ) + { + log.debug( "Starting new socket node." ); + } + new Thread( new LateralJGReceiverConnection( mes, ilcl ) ).start(); + } + else + { + if ( log.isDebugEnabled() ) + { + log.debug( "Received unknown object from jgroups = " + obj ); + } + } + } + catch ( ChannelNotConnectedException cnce ) + { + if ( conProbCnt % 20 == 0 ) + { + log.warn( cnce ); + } + conProbCnt++; + + if ( conProbCnt >= 2000 ) + { + log.error( "Couldn't get connected to group after " + conProbCnt + " tries" ); + break; + } + // slow the connection try process down + synchronized ( this ) + { + this.wait( 100 ); + } + // this will cycle unitl connected and eat up the processor + // need to throw out and recover + // seems to periodically require about 50 tries. + } + catch ( Exception e ) + { + // should zombie + log.error( "problem receiving", e ); + } + + } + } + catch ( Exception e ) + { + log.error( "Major connection problem", e ); + } + } + + /** + * Constructor for the LateralJGReceiver object + * + * @param ilcl + * @param ilca + */ + public LateralJGReceiver( ILateralCacheAttributes ilca, ILateralCacheJGListener ilcl ) + { + + this.ilcl = ilcl; + this.ilca = ilca; + if ( log.isDebugEnabled() ) + { + log.debug( "ilcl = " + ilcl ); + } + } +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiverConnection.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiverConnection.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiverConnection.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGReceiverConnection.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,139 @@ +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.Serializable; + +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.LateralElementDescriptor; +import org.apache.jcs.auxiliary.lateral.javagroups.behavior.ILateralCacheJGListener; +import org.jgroups.Message; + +/** + * Separate thread run when a command comes into the LateralJGReceiver. + * + * @version $Id: LateralJGReceiverConnection.java,v 1.7 2002/02/15 04:33:37 + * jtaylor Exp $ + */ +public class LateralJGReceiverConnection + implements Runnable +{ + + private final static Log log = LogFactory.getLog( LateralJGReceiverConnection.class ); + + //private Channel javagroups; + private Message mes; + + private ILateralCacheJGListener ilcl; + + /** + * Constructor for the LateralJGReceiverConnection object + * + * @param mes + * The JGroups message + * @param ilcl + */ + public LateralJGReceiverConnection( Message mes, ILateralCacheJGListener ilcl ) + { + this.ilcl = ilcl; + this.mes = mes; + } + + /** + * Main processing method for the LateralJGReceiverConnection object + * + * @return + * @param led + */ + public void run() + { + Object obj = null; + try + { + obj = mes.getObject(); + LateralElementDescriptor led = (LateralElementDescriptor)obj; + if ( led == null ) + { + log.warn( "LateralElementDescriptor is null! Can't do anything." ); + } + else + { + if ( led.requesterId == LateralCacheInfo.listenerId ) + { + log.debug( "from self" ); + } + else + { + if ( log.isDebugEnabled() ) + { + log.debug( "receiving LateralElementDescriptor from another, led = " + ", led = " + led + + ", led.command = " + led.command + ", led.ce = " + led.ce + ", ilcl = " + ilcl ); + } + if ( led.command == LateralElementDescriptor.UPDATE ) + { + ilcl.handlePut( led.ce ); + } + else if ( led.command == LateralElementDescriptor.REMOVE ) + { + ilcl.handleRemove( led.ce.getCacheName(), led.ce.getKey() ); + } + else if ( led.command == LateralElementDescriptor.GET ) + { + /* Serializable obj = */getAndRespond( led.ce.getCacheName(), led.ce.getKey() ); + + } + } + } + + } + catch ( java.io.EOFException e ) + { + log.info( "Caught java.io.EOFException closing connection." ); + } + catch ( java.net.SocketException e ) + { + log.info( "Caught java.net.SocketException closing connection." ); + } + catch ( Exception e ) + { + log.error( "Unexpected exception. obj = " + obj, e ); + } + } + + /** + * Send back the object if found. + * + * @return The {3} value + * @param cacheName + * @param key + * @exception Exception + */ + private Serializable getAndRespond( String cacheName, Serializable key ) + throws Exception + { + Serializable obj = ilcl.handleGet( cacheName, key ); + + if ( log.isDebugEnabled() ) + { + log.debug( "obj = " + obj ); + } + + return obj; + } +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGSender.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGSender.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGSender.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGSender.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,309 @@ +package org.apache.jcs.auxiliary.lateral.javagroups; + +/* + * Copyright 2002-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.Iterator; +import java.util.Vector; + +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.LateralElementDescriptor; +import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes; +import org.apache.jcs.auxiliary.lateral.javagroups.behavior.IJGConstants; +import org.apache.jcs.engine.CacheElement; +import org.apache.jcs.engine.behavior.ICacheElement; +import org.jgroups.Channel; +import org.jgroups.Message; +import org.jgroups.blocks.GroupRequest; +import org.jgroups.blocks.MethodCall; +import org.jgroups.blocks.RpcDispatcher; +import org.jgroups.util.RspList; + +/** + * This class is based on the log4j SocketAppender class. I'm using a differnet + * repair structure, so it is significant;y different. + * + * @version $Id: LateralJGSender.java 240226 2005-08-26 12:47:59Z asmuts $ + */ +public class LateralJGSender + implements IJGConstants +{ + private final static Log log = LogFactory.getLog( LateralJGSender.class ); + + private ILateralCacheAttributes ilca; + + int port = 1111; + + private Channel javagroups; + + private RpcDispatcher disp; + + private JGConnectionHolder holder; + + int counter = 0; + + /** + * Constructor for the LateralJGSender object + * + * @param lca + * @exception IOException + */ + public LateralJGSender( ILateralCacheAttributes lca ) + throws IOException + { + this.ilca = lca; + init(); + } + + /** + * Create holder. + * + * @exception IOException + */ + protected void init() + throws IOException + { + + try + { + log.debug( "Attempting ccreate channel." ); + + holder = JGConnectionHolder.getInstance( ilca ); + javagroups = holder.getChannel(); + + if ( javagroups == null ) + { + throw new IOException( "javagroups is null" ); + } + + } + catch ( java.net.ConnectException e ) + { + log.debug( "Remote host refused connection." ); + throw e; + } + catch ( Exception e ) + { + log.debug( "Could not connect to channel.", e ); + throw new IOException( e.getMessage() ); + } + + } + + // end constructor + + /** + * Sends commands to the lateral cache listener. + * + * @param led + * @exception IOException + */ + public void send( LateralElementDescriptor led ) + throws IOException + { + log.debug( "sending LateralElementDescriptor" ); + + if ( led == null ) + { + return; + } + + try + { + + Message send_msg = new Message( null, null, led ); + + javagroups.send( send_msg ); + + } + catch ( Exception e ) + { + log.error( "Detected problem with connection: " + e ); + throw new IOException( e.getMessage() ); + } + + } + + /** + * Sends commands to the lateral cache listener and gets a response. + * + * @return + * @param led + * @exception IOException + */ + public ICacheElement sendAndReceive( LateralElementDescriptor led ) + throws IOException + { + ICacheElement ice = null; + + log.debug( "SendAndReceive led" ); + + if ( led == null ) + { + return null; + } + + try + { + + try + { + + disp = holder.getDispatcher(); + Object[] args = { led.ce.getCacheName(), led.ce.getKey() }; + String[] sigs = { java.lang.String.class.getName(), java.io.Serializable.class.getName() }; + MethodCall meth = new MethodCall( "handleGet", args, sigs ); + RspList rsp_list = disp.callRemoteMethods( null, meth, GroupRequest.GET_ALL, 1000 ); + + log.debug( "rsp_list = " + rsp_list ); + Vector vec = rsp_list.getResults(); + log.debug( "rsp_list size = " + vec.size() ); + Iterator it = vec.iterator(); + + while ( it.hasNext() ) + { + ice = (ICacheElement) it.next(); + if ( ice != null ) + { + break; + } + } + + } + catch ( Exception e ) + { + log.error( e ); + } + + } + catch ( Exception e ) + { + log.error( "Detected problem with connection.", e ); + throw new IOException( e.getMessage() ); + } + // } + return ice; + }// end sendAndReceive + + // Service Methods // + /** + * Description of the Method + * + * @param item + * @param requesterId + * @exception IOException + */ + public void update( ICacheElement item, long requesterId ) + throws IOException + { + LateralElementDescriptor led = new LateralElementDescriptor( item ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.UPDATE; + send( led ); + } + + /** + * Description of the Method + * + * @param cacheName + * @param key + * @exception IOException + */ + public void remove( String cacheName, Serializable key ) + throws IOException + { + remove( cacheName, key, LateralCacheInfo.listenerId ); + } + + /** + * Description of the Method + * + * @param cacheName + * @param key + * @param requesterId + * @exception IOException + */ + public void remove( String cacheName, Serializable key, long requesterId ) + throws IOException + { + CacheElement ce = new CacheElement( cacheName, key, null ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.REMOVE; + send( led ); + } + + /** + * Description of the Method + * + * @exception IOException + */ + public void release() + throws IOException + { + // nothing needs to be done + } + + /** + * Closes connection used by all LateralJGSenders for this lateral + * conneciton. Dispose request should come into the facade and be sent to + * all lateral cache sevices. The lateral cache service will then call this + * method. + * + * @param cache + * @exception IOException + */ + public void dispose( String cache ) + throws IOException + { + + } + + /** + * Description of the Method + * + * @param cacheName + * @exception IOException + */ + public void removeAll( String cacheName ) + throws IOException + { + removeAll( cacheName, LateralCacheInfo.listenerId ); + } + + /** + * Description of the Method + * + * @param cacheName + * @param requesterId + * @exception IOException + */ + public void removeAll( String cacheName, long requesterId ) + throws IOException + { + CacheElement ce = new CacheElement( cacheName, "ALL", null ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.REMOVEALL; + send( led ); + } + +} +// end class Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGService.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGService.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGService.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/LateralJGService.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,289 @@ +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.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Serializable; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes; +import org.apache.jcs.auxiliary.lateral.LateralCacheInfo; +import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor; +import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes; +import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheObserver; +import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService; +import org.apache.jcs.engine.CacheElement; +import org.apache.jcs.engine.behavior.ICacheElement; +import org.apache.jcs.engine.behavior.ICacheListener; + +/** + * A lateral cache service implementation. + * + * @version $Id: LateralJGService.java 240226 2005-08-26 12:47:59Z asmuts $ + */ +public class LateralJGService + implements ILateralCacheService, ILateralCacheObserver +{ + private final static Log log = LogFactory.getLog( LateralJGService.class ); + + private ILateralCacheAttributes ilca; + + private LateralJGSender sender; + + /** + * Constructor for the LateralJGService object + * + * @param lca + * @exception IOException + */ + public LateralJGService( ILateralCacheAttributes lca ) + throws IOException + { + this.ilca = lca; + + try + { + log.debug( "creating sender" ); + + sender = new LateralJGSender( lca ); + + log.debug( "created sender" ); + } + catch ( IOException e ) + { + + log.error( "Could not create sender to [" + lca.getJGChannelProperties() + "]", e ); + + throw e; + } + } + + // -------------------------------------------------------- Service Methods + + /** + * @param item + * @exception IOException + */ + public void update( ICacheElement item ) + throws IOException + { + update( item, LateralCacheInfo.listenerId ); + } + + /** + * @param item + * @param requesterId + * @exception IOException + */ + public void update( ICacheElement item, long requesterId ) + throws IOException + { + LateralElementDescriptor led = new LateralElementDescriptor( item ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.UPDATE; + sender.send( led ); + } + + /** + * @param cacheName + * @param key + * @exception IOException + */ + public void remove( String cacheName, Serializable key ) + throws IOException + { + remove( cacheName, key, LateralCacheInfo.listenerId ); + } + + /** + * @param cacheName + * @param key + * @param requesterId + * @exception IOException + */ + public void remove( String cacheName, Serializable key, long requesterId ) + throws IOException + { + CacheElement ce = new CacheElement( cacheName, key, null ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.REMOVE; + sender.send( led ); + } + + /** + * @exception IOException + */ + public void release() + throws IOException + { + // nothing needs to be done + } + + /** + * Will close the connection. + * + * @param cache + * @exception IOException + */ + public void dispose( String cache ) + throws IOException + { + sender.dispose( cache ); + } + + /** + * @return + * @param cacheName + * @param key + * @exception IOException + */ + public ICacheElement get( String cacheName, Serializable key ) + throws IOException + { + //p( "get(cacheName,key,container)" ); + CacheElement ce = new CacheElement( cacheName, key, null ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + //led.requesterId = requesterId; // later + led.command = LateralElementDescriptor.GET; + return sender.sendAndReceive( led ); + //return null; + // nothing needs to be done + } + + /** + * @param cacheName + * @exception IOException + */ + public void removeAll( String cacheName ) + throws IOException + { + removeAll( cacheName, LateralCacheInfo.listenerId ); + } + + /** + * @param cacheName + * @param requesterId + * @exception IOException + */ + public void removeAll( String cacheName, long requesterId ) + throws IOException + { + CacheElement ce = new CacheElement( cacheName, "ALL", null ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + led.requesterId = requesterId; + led.command = LateralElementDescriptor.REMOVEALL; + sender.send( led ); + } + + /** + * Gets the set of keys of objects currently in the group throws + * UnsupportedOperationException + */ + public Set getGroupKeys( String cacheName, String group ) + { + if ( true ) + { + throw new UnsupportedOperationException( "Groups not implemented." ); + } + return null; + } + + /** + * @param args + */ + public static void main( String args[] ) + { + try + { + LateralJGSender sender = new LateralJGSender( new LateralCacheAttributes() ); + + // process user input till done + boolean notDone = true; + String message = null; + // wait to dispose + BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); + + while ( notDone ) + { + System.out.println( "enter mesage:" ); + message = br.readLine(); + CacheElement ce = new CacheElement( "test", "test", message ); + LateralElementDescriptor led = new LateralElementDescriptor( ce ); + sender.send( led ); + } + } + catch ( Exception e ) + { + System.out.println( e.toString() ); + } + } + + // ILateralCacheObserver methods, do nothing here since + // the connection is not registered, the udp service is + // is not registered. + + /** + * @param cacheName + * The feature to be added to the CacheListener attribute + * @param obj + * The feature to be added to the CacheListener attribute + * @exception IOException + */ + public void addCacheListener( String cacheName, ICacheListener obj ) + throws IOException + { + // Empty + } + + /** + * @param obj + * The feature to be added to the CacheListener attribute + * @exception IOException + */ + public void addCacheListener( ICacheListener obj ) + throws IOException + { + // Empty + } + + /** + * @param cacheName + * @param obj + * @exception IOException + */ + public void removeCacheListener( String cacheName, ICacheListener obj ) + throws IOException + { + // Empty + } + + /** + * @param obj + * @exception IOException + */ + public void removeCacheListener( ICacheListener obj ) + throws IOException + { + // Empty + } + +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/IJGConstants.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/IJGConstants.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/IJGConstants.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/IJGConstants.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,28 @@ +package org.apache.jcs.auxiliary.lateral.javagroups.behavior; + +/* + * 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. + */ + +public interface IJGConstants +{ + + public static final String HANDLERNAME = "LATERAL_JG_CACHE"; + + public static final String DEFAULT_JG_GROUP_NAME = "JCS_CACHE"; + + public static final String RPC_JG_GROUP_NAME = "RPC_JCS_CACHE"; + +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/ILateralCacheJGListener.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/ILateralCacheJGListener.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/ILateralCacheJGListener.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/behavior/ILateralCacheJGListener.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,40 @@ +package org.apache.jcs.auxiliary.lateral.javagroups.behavior; + +/* + * 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.Serializable; +import java.io.IOException; + +import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener; + +/** + * Listens for lateral cache event notification. + * + * @version $Id: ILateralCacheJGListener.java 224346 2005-06-04 02:01:59Z asmuts $ + */ +public interface ILateralCacheJGListener + extends ILateralCacheListener +{ + + /** Description of the Method */ + public void init(); + + /** Tries to get a requested item from the cache. */ + public Serializable handleGet( String cacheName, Serializable key ) + throws IOException; + +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGRpcOpener.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGRpcOpener.java?rev=280251&view=auto ============================================================================== --- jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGRpcOpener.java (added) +++ jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGRpcOpener.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,120 @@ +package org.apache.jcs.auxiliary.lateral.javagroups.utils; + +/* + * 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.lateral.behavior.ILateralCacheAttributes; +import org.apache.jcs.auxiliary.lateral.javagroups.behavior.ILateralCacheJGListener; +import org.jgroups.Channel; +import org.jgroups.JChannel; +import org.jgroups.blocks.RpcDispatcher; + +/** + * Socket openere that will timeout on the initial connect rather than block + * forever. Technique from core java II. + * + * @version $Id: JGRpcOpener.java 234393 2005-08-22 00:12:06Z asmuts $ + */ +public class JGRpcOpener + implements Runnable +{ + + private final static Log log = LogFactory.getLog( JGRpcOpener.class ); + + //private Socket socket; + private Channel rpcCh; + + private RpcDispatcher disp; + + private String groupName; + + private ILateralCacheJGListener ilcl; + + private ILateralCacheAttributes ilca; + + /** Constructor for the SocketOpener object + * @param ilcl + * @param ilca + * @param timeOut + * @param groupName + * @return*/ + public static RpcDispatcher openSocket( ILateralCacheJGListener ilcl, ILateralCacheAttributes ilca, int timeOut, + String groupName ) + { + JGRpcOpener opener = new JGRpcOpener( ilcl, ilca, groupName ); + Thread t = new Thread( opener ); + t.start(); + try + { + t.join( timeOut ); + } + catch ( InterruptedException ire ) + { + log.error( ire ); + } + return opener.getSocket(); + } + + /** + * Constructor for the SocketOpener object + * @param ilcl + * @param ilca + * @param groupName + * + */ + public JGRpcOpener( ILateralCacheJGListener ilcl, ILateralCacheAttributes ilca, String groupName ) + { + this.rpcCh = null; + this.ilcl = ilcl; + this.ilca = ilca; + this.groupName = groupName; + } + + /** Main processing method for the SocketOpener object */ + public void run() + { + try + { + + //String props="UDP(mcast_addr=" + ilca.getUdpMulticastAddr() + + // ";mcast_port=" + ilca.getUdpMulticastPort()+ + // "):PING:MERGE2(min_interval=5000;max_interval=10000):FD:STABLE:NAKACK:UNICAST:FLUSH:GMS:VIEW_ENFORCER:QUEUE"; + rpcCh = new JChannel( ilca.getJGChannelProperties() ); + rpcCh.setOpt( Channel.LOCAL, Boolean.FALSE ); + disp = new RpcDispatcher( rpcCh, null, null, ilcl ); + rpcCh.connect( groupName ); + + if ( log.isInfoEnabled() ) + { + log.info( "Is Connected = " + rpcCh.isConnected() ); + } + + } + catch ( Exception e ) + { + log.error( "Problem getting dispatcher.", e ); + } + } + + /** Gets the socket attribute of the SocketOpener object + * @return*/ + public RpcDispatcher getSocket() + { + return disp; + } +} Added: jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGSocketOpener.java URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/lateral/javagroups/utils/JGSocketOpener.java?rev=280251&view=auto ============================================================================== --- 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/lateral/javagroups/utils/JGSocketOpener.java Sun Sep 11 21:26:41 2005 @@ -0,0 +1,121 @@ +package org.apache.jcs.auxiliary.lateral.javagroups.utils; + +/* + * 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.lateral.behavior.ILateralCacheAttributes; +import org.jgroups.Channel; +import org.jgroups.ChannelFactory; +import org.jgroups.JChannelFactory; + +/** + * Socket openere that will timeout on the initial connect rather than block + * forever. + * + * @version $Id: JGSocketOpener.java 234393 2005-08-22 00:12:06Z asmuts $ + */ +public class JGSocketOpener + implements Runnable +{ + + private final static Log log = LogFactory.getLog( JGSocketOpener.class ); + + private ILateralCacheAttributes lca; + + private Channel javagroups; + + private String groupName; + + /** + * Constructor for the <code>SocketOpener</code> object. + * @param lca + * @param timeOut + * @param groupName + * @return + */ + public static Channel openSocket( ILateralCacheAttributes lca, int timeOut, String groupName ) + { + JGSocketOpener opener = new JGSocketOpener( lca, groupName ); + Thread t = new Thread( opener ); + t.start(); + try + { + t.join( timeOut ); + } + catch ( InterruptedException ire ) + { + log.error( "Failed of connect in within timout of " + timeOut, ire ); + } + return opener.getSocket(); + } + + /** + * Constructor for the SocketOpener object + * @param lca + * @param groupName + * + * @param host + * @param port + */ + public JGSocketOpener( ILateralCacheAttributes lca, String groupName ) + { + this.javagroups = null; + this.lca = lca; + this.groupName = groupName; + } + + /** + * Main processing method for the <code>SocketOpener</code> object. + */ + public void run() + { + try + { + + ChannelFactory factory = new JChannelFactory(); + + // Create a channel based on 'channelProperties' from the config + Channel channel = factory.createChannel( lca.getJGChannelProperties() ); + + javagroups = channel; //new JChannel( lca.getJGChannelProperties() + // ); + // don't send local + javagroups.setOpt( Channel.LOCAL, Boolean.FALSE ); + + javagroups.connect( groupName ); + + if ( log.isInfoEnabled() ) + { + log.info( "Is Connected = " + javagroups.isConnected() ); + } + + } + catch ( Exception e ) + { + log.error( "Problem connecting to channel.", e ); + } + } + + /** + * Gets the socket attribute of the <code>SocketOpener</code> object. + */ + public Channel getSocket() + { + return javagroups; + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
