asmuts 02/01/14 22:24:03
Added: src/java/org/apache/stratum/jcs/auxiliary/lateral/http/remove
DeleteLateralCacheMulticaster.java
DeleteLateralCacheUnicaster.java
Log:
the start of a lateral cache system
needs some work
Revision Changes Path
1.1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/http/remove/DeleteLateralCacheMulticaster.java
Index: DeleteLateralCacheMulticaster.java
===================================================================
package org.apache.stratum.jcs.auxiliary.lateral.http.remove;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.apache.stratum.jcs.engine.memory.*;
import org.apache.stratum.jcs.engine.behavior.*;
import org.apache.stratum.jcs.utils.reuse.*;
import org.apache.stratum.jcs.engine.*;
import org.apache.stratum.jcs.utils.log.*;
/*
* Used to multi-cast a key/val pair to the named cache on multiple servers.
*/
public class DeleteLateralCacheMulticaster {
// must get servletName from the props file
private final String servlet;
private final String hashtableName;
private final String key;
private final ArrayList servers;
protected Logger log;
////////////////////////////////////////////////////////////////////////
public DeleteLateralCacheMulticaster ( String hashtableName, String key, ArrayList
servers, String servlet) {
this.hashtableName = hashtableName;
this.key = key;
this.servers = servers;
this.servlet = servlet;
LoggerManager loggerMgr = LoggerManager.getInstance();
log = loggerMgr.getLogger(this);
log.setLogLevel( log.DEBUG );
if ( log.logLevel >= log.DEBUG ) {
log.debug("In DistCacheMulticaster");
}
} // end constructor
/** Multi-casts the deltes to the distributed servers. */
public void multicast () {
ThreadPoolManager tpm = ThreadPoolManager.getInstance();
Iterator it = servers.iterator();
//p( "iterating through servers" );
while ( it.hasNext() ) {
String url = (String)it.next() + servlet;
//p( "url = " + url );
tpm.runIt(new DeleteLateralCacheUnicaster( hashtableName, key, url) );
}
return;
} // end multicast
////////////////////////////////////////
public static void p( String s ) {
System.out.println( s );
//log.debug( s );
}
} // end class
1.1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/auxiliary/lateral/http/remove/DeleteLateralCacheUnicaster.java
Index: DeleteLateralCacheUnicaster.java
===================================================================
package org.apache.stratum.jcs.auxiliary.lateral.http.remove;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import org.apache.stratum.jcs.engine.memory.*;
import org.apache.stratum.jcs.engine.behavior.*;
import org.apache.stratum.jcs.engine.*;
import org.apache.stratum.jcs.utils.reuse.*;
import org.apache.stratum.jcs.utils.log.*;
/**
* Used to uni-cast a ICacheItem to the named cache on the target server.
*/
public class DeleteLateralCacheUnicaster implements IThreadPoolRunnable {
private final String hashtableName;
private final String key;
private String urlStr;
private final Logger log;
private URLConnection conn;
protected boolean debug = true;
/**
* Constructs with the given ICacheItem and the url of the target server.
*/
public DeleteLateralCacheUnicaster( String hashtableName, String key, String
urlStr) {
this.hashtableName = hashtableName;
this.key = key;
this.urlStr = urlStr;
log = LoggerManager.getLogger( this );
log.debug("In DeleteLateralCacheUnicaster, " + Thread.currentThread().getName()
);
}
/**
* Called when this object is first loaded in the thread pool.
* Important: all workers in a pool must be of the same type,
* otherwise the mechanism becomes more complex.
*/
public Object[] getInitData() { return null; }
/**
* Sends a ICacheItem to the target server.
* This method will be executed in one of the pool's threads. The
* thread will be returned to the pool.
*/
// Todo: error recovery and retry.
public void runIt(Object thData[]) {
long start = System.currentTimeMillis();
try {
if ( !urlStr.startsWith("http://") ) {
urlStr = "http://" + urlStr;
}
urlStr = urlStr + "?hashtableName=" + hashtableName + "&key=" + key;
log.debug( "urlStr = " + urlStr );
callClearCache( urlStr );
} catch (Exception e) {
log.error( e );
}// end catch
if ( log.logLevel >= log.DEBUG ) {
log.debug( "delete took " + String.valueOf( System.currentTimeMillis() - start
) + " millis\n" );
}
log.flush();
return;
} // end runIt
///////////////////////////////////////////////
public void callClearCache( String ccServletURL ) {
URL clear;
URLConnection clearCon;
InputStream in;
OutputStream out;
try {
clear = new URL( ccServletURL );
clearCon = clear.openConnection();
clearCon.setDoOutput(true);
clearCon.setDoInput(true);
//clearCon.connect();
out = clearCon.getOutputStream();
in = clearCon.getInputStream();
int cur = in.read();
while(cur != -1) {
cur = in.read();
}
out.close();
in.close();
// System.out.println("closed inputstream" );
} catch( Exception e ) {
log.logEx( e );
}
finally {
//in.close();
out = null;
in = null;
clearCon = null;
clear = null;
log.info( "called clear cache for " + ccServletURL );
return;
}
} // end callClearCache
////////////////////////////////////////
public static void p( String s ) {
System.out.println( s );
//log.debug( s );
}
} // end class
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>