asmuts 02/01/14 22:30:54
Added: src/java/org/apache/stratum/jcs/auxiliary/remote/server/group
RemoteGroupCacheServer.java
RemoteGroupCacheServerFactory.java
Log:
special group functionality
Revision Changes Path
1.1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/server/group/RemoteGroupCacheServer.java
Index: RemoteGroupCacheServer.java
===================================================================
package org.apache.stratum.jcs.auxiliary.remote.server.group;
/////////////////////////////////////
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.*;
import org.apache.stratum.jcs.access.*;
import org.apache.stratum.jcs.auxiliary.disk.*;
import org.apache.stratum.jcs.engine.*;
import org.apache.stratum.jcs.engine.behavior.*;
import org.apache.stratum.jcs.engine.control.*;
import org.apache.stratum.jcs.engine.group.*;
import org.apache.stratum.jcs.auxiliary.remote.*;
import org.apache.stratum.jcs.auxiliary.remote.server.*;
import org.apache.stratum.jcs.auxiliary.remote.behavior.*;
import org.apache.stratum.jcs.utils.reuse.*;
/**
* Provides session remote cache services.
*/
public class RemoteGroupCacheServer extends RemoteCacheServer
{
/**
* Remote Cache Server.
*/
protected RemoteGroupCacheServer(String prop) throws IOException,
NotBoundException {
super(prop);
}
protected CompositeCacheManager createCacheManager(String prop) {
return GroupCacheManagerFactory.getInstance(prop == null ? "/remote.cache.ccf" :
prop);
}
/////////////////////// Implements the ICacheServiceAdmin interface.
//////////////////
public void shutdown() throws IOException
{
RemoteGroupCacheServerFactory.shutdownImpl("", Registry.REGISTRY_PORT);
}
public void shutdown(String host, int port) throws IOException
{
RemoteGroupCacheServerFactory.shutdownImpl(host, port);
}
}
1.1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/remote/server/group/RemoteGroupCacheServerFactory.java
Index: RemoteGroupCacheServerFactory.java
===================================================================
package org.apache.stratum.jcs.auxiliary.remote.server.group;
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.util.*;
import org.apache.stratum.jcs.engine.behavior.*;
import org.apache.stratum.jcs.engine.control.*;
import org.apache.stratum.jcs.engine.*;
import org.apache.stratum.jcs.access.*;
import org.apache.stratum.jcs.engine.control.Cache;
import org.apache.stratum.jcs.auxiliary.disk.*;
import org.apache.stratum.jcs.auxiliary.remote.*;
import org.apache.stratum.jcs.auxiliary.remote.server.*;
import org.apache.stratum.jcs.auxiliary.remote.behavior.*;
import org.apache.stratum.jcs.utils.reuse.*;
import org.apache.stratum.jcs.utils.log.*;
import com.mortbay.Jetty.*;
import com.mortbay.Util.Code;
/**
* Provides remote session cache services.
*/
public class RemoteGroupCacheServerFactory
implements IRemoteCacheConstants {
/** The single instance of the RemoteGroupCacheServer object. */
private static RemoteGroupCacheServer instance;
private static String serviceName;
static boolean debug = false;
private static Logger log = LoggerManager.getLogger(
"group_remotegroupcacheserverfactory" );
private RemoteGroupCacheServerFactory () {
}
/////////////////////// Statup/shutdown methods. //////////////////
/**
* Starts up the remote session cache server on this JVM, and binds it to the
registry on the
* given host and port.
*/
public static void startup (String host, int port, String propFile) throws
IOException,
NotBoundException {
if (instance != null) {
throw new IllegalArgumentException("Server already started.");
}
Properties prop = null;
synchronized (RemoteGroupCacheServer.class) {
if (instance != null) {
return;
}
prop = RemoteUtils.loadProps(propFile);
instance = new RemoteGroupCacheServer(propFile);
if (host == null) {
host = "";
}
// Register the RemoteGroupCacheServer remote object in the registry.
serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME,
REMOTE_CACHE_SERVICE_VAL).trim();
log.info("main> binding server to " + host + ":" + port + " with the name " +
serviceName);
try {
Naming.rebind("//" + host + ":" + port + "/" + serviceName, instance);
} catch (MalformedURLException ex) {
// impossible case.
throw new IllegalArgumentException(ex.getMessage() + "; host=" + host
+ ", port=" + port);
}
}
// Start up jetty inside remote cache, useful for monitoring
boolean jettyOn = Boolean.valueOf( prop.getProperty(JETTY_ON, "true" ).trim()
).booleanValue();
p( "jettyOn = " + jettyOn );
if ( jettyOn ) {
String jettyXml = prop.getProperty(JETTY_XML,
"C:/dev/jakarta-turbine-stratum/props/myjetty.xml").trim();
startupJetty(new String[]{jettyXml});
}
} ///////////
////////////////////////////////////////////////////
private static void startupJetty(String[] arg) {
String[] dftConfig={"C:/dev/jakarta-turbine-stratum/props/myjetty.xml"};
if (arg.length==0) {
System.err.println("Using default configuration: etc/demo.xml");
arg=dftConfig;
}
for (int i=0;i<arg.length;i++)
{
try
{
new Server(arg[i]).start();
p( "started jetty" );
}
catch(Exception e)
{
Code.warning(e);
}
}
}
/////////////////////////////////////////////////////////////////////////
static void shutdownImpl (String host, int port) throws IOException {
if (instance == null) {
return;
}
synchronized (RemoteGroupCacheServer.class) {
if (instance == null) {
return;
}
p("Unbinding host=" + host + ", port=" + port + ", serviceName=" +
serviceName);
try {
Naming.unbind("//" + host + ":" + port + "/" + serviceName);
} catch (MalformedURLException ex) {
// impossible case.
throw new IllegalArgumentException(ex.getMessage() + "; host=" + host
+ ", port=" + port + ", serviceName=" + serviceName);
} catch (NotBoundException ex) {
//ignore.
}
instance.release();
instance = null;
// TODO: safer exit ?
try {
Thread.currentThread().sleep(2000);
} catch (InterruptedException ex) {}
System.exit(0);
}
}
/**
* Creates an local Remote registry on the default port,
* starts up the remote session cache server, and binds it to the registry.
*/
public static void main (String[] args) throws Exception {
Properties prop = args.length > 0 ? RemoteUtils.loadProps(args[0]) : new
Properties();
// shutdown
if (args.length > 0 && args[0].toLowerCase().indexOf("-shutdown") != -1) {
p( "Sutting down cache" );
try {
int port=Registry.REGISTRY_PORT;
if (args.length > 1) {
port = Integer.parseInt(args[1]);
}
String serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME,
REMOTE_CACHE_SERVICE_VAL).trim();
// shutdown.
String registry = "//:" + port + "/" + serviceName;
//if (debug) {
p("looking up server " + registry);
//}
Object obj = Naming.lookup(registry);
//if (debug) {
p("server found");
//}
p( "obj = " + obj );
IRemoteCacheServiceAdmin admin = (IRemoteCacheServiceAdmin)obj;
try {
admin.shutdown("", port);
} catch ( Exception er ) {
// ignore the error
// the connection will be closed by the server
}
} catch (Exception ex) {
p( ex.toString() );
ex.printStackTrace( System.out );
}
p("done.");
System.exit(0);
}
// STATS
if (args.length > 0 && args[0].toLowerCase().indexOf("-stats") != -1) {
p( "getting cache stats" );
try {
int port=Registry.REGISTRY_PORT;
if (args.length > 1) {
port = Integer.parseInt(args[1]);
}
String serviceName = prop.getProperty(REMOTE_CACHE_SERVICE_NAME,
REMOTE_CACHE_SERVICE_VAL).trim();
String registry = "//:" + port + "/" + serviceName;
p("looking up server " + registry);
Object obj = Naming.lookup(registry);
p("server found");
p( "obj = " + obj );
IRemoteCacheServiceAdmin admin = (IRemoteCacheServiceAdmin)obj;
try {
p( admin.getStats() );
} catch ( Exception es ) {
p( es.toString() );
}
} catch (Exception ex) {
p( ex.toString() );
ex.printStackTrace( System.out );
}
p("done.");
System.exit(0);
}
// startup.
int port;
try {
port = Integer.parseInt(prop.getProperty("registry.port"));
} catch (NumberFormatException ex) {
port = Registry.REGISTRY_PORT;
}
String host = prop.getProperty("registry.host");
if (host == null || host.trim().equals("") || host.trim().equals("localhost")) {
p("main> creating registry on the localhost");
port = RemoteUtils.createRegistry(port);
}
p("main> starting up RemoteGroupCacheServer");
RemoteGroupCacheServerFactory.startup(host, port, args.length > 0 ? args[0] :
null);
p("main> done");
}
private static void p (String s) {
System.out.println("RemoteGroupCacheServer:" + s + " >" +
Thread.currentThread().getName());
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>