use of jp.ossc.nimbus.util.WaitSynchronizeMonitor in project nimbus by nimbus-org.
the class HttpResponseCacheInterceptorService method getHttpResponseCache.
private HttpResponseCache getHttpResponseCache(String path) throws InterruptedException {
HttpResponseCache responseCache = (HttpResponseCache) cacheMap.get(path);
if (responseCache != null) {
return responseCache;
}
SynchronizeMonitor waitMonitor = (SynchronizeMonitor) lockMap.get(path);
if (waitMonitor == null) {
responseCache = (HttpResponseCache) cacheMap.get(path);
if (responseCache == null) {
waitMonitor = (SynchronizeMonitor) lockMap.putIfAbsent(path, new WaitSynchronizeMonitor());
} else {
return responseCache;
}
}
if (waitMonitor == null) {
return null;
}
waitMonitor.initMonitor();
if (waitTimeout > 0) {
if (waitMonitor.waitMonitor(waitTimeout)) {
return getHttpResponseCache(path);
} else {
return null;
}
} else {
waitMonitor.waitMonitor();
return getHttpResponseCache(path);
}
}
use of jp.ossc.nimbus.util.WaitSynchronizeMonitor in project nimbus by nimbus-org.
the class ClientConnectionImpl method send.
private void send(ClientMessage message) throws IOException, MessageSendException {
SynchronizeMonitor responseMonitor = null;
Short reqId = null;
boolean isBye = message.getMessageType() == ClientMessage.MESSAGE_BYE;
try {
if (!isBye && isAcknowledge) {
if (requestMonitorMap == null) {
requestMonitorMap = new HashMap();
}
synchronized (requestMonitorMap) {
message.setRequestId(requestId++);
responseMonitor = new WaitSynchronizeMonitor();
responseMonitor.initMonitor();
reqId = new Short(message.getRequestId());
requestMonitorMap.put(reqId, responseMonitor);
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (externalizer == null) {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(message);
oos.flush();
} else {
externalizer.writeExternal(message, baos);
}
byte[] bytes = baos.toByteArray();
synchronized (this) {
if (socket == null) {
throw new MessageSendException("No connected.");
}
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
dos.writeInt(bytes.length);
dos.write(bytes);
dos.flush();
}
if (!isBye && isAcknowledge) {
try {
if (!responseMonitor.waitMonitor(responseTimeout)) {
throw new MessageSendException("Acknowledge is timed out.");
}
} catch (InterruptedException e) {
throw new MessageSendException("Acknowledge is interrupted.", e);
}
}
} finally {
if (!isBye && isAcknowledge) {
synchronized (requestMonitorMap) {
requestMonitorMap.remove(reqId);
}
}
}
}
use of jp.ossc.nimbus.util.WaitSynchronizeMonitor in project nimbus by nimbus-org.
the class ServiceManagerFactory method main.
/**
* コンパイルコマンドを実行する。<p>
* <pre>
* コマンド使用方法:
* java jp.ossc.nimbus.core.ServiceManagerFactory [options] [paths]
*
* [options]
*
* [-validate]
* サービス定義をDTDで検証する。
*
* [-server]
* メインスレッドを待機させて、サーバとして動かす。
*
* [-help]
* ヘルプを表示します。
*
* [paths]
* ロードするサービス定義ファイルのパス
*
* 使用例 :
* java -classpath classes;lib/nimbus.jar jp.ossc.nimbus.core.ServiceManagerFactory service-definition.xml
* </pre>
*
* @param args コマンド引数
* @exception Exception コンパイル中に問題が発生した場合
*/
public static void main(String[] args) throws Exception {
if (args.length != 0 && args[0].equals("-help")) {
usage();
return;
}
final List servicePaths = new ArrayList();
boolean validate = false;
boolean server = false;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-server")) {
server = true;
} else if (args[i].equals("-validate")) {
validate = true;
} else {
servicePaths.add(args[i]);
}
}
if (servicePaths.size() == 0) {
usage();
return;
}
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
for (int i = servicePaths.size(); --i >= 0; ) {
ServiceManagerFactory.unloadManager((String) servicePaths.get(i));
}
}
}));
for (int i = 0, max = servicePaths.size(); i < max; i++) {
if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
Thread.sleep(1000);
System.exit(-1);
}
}
if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
Thread.sleep(1000);
System.exit(-1);
}
if (server) {
WaitSynchronizeMonitor lock = new WaitSynchronizeMonitor();
synchronized (lock) {
lock.initMonitor();
try {
lock.waitMonitor();
} catch (InterruptedException ignore) {
}
}
}
}
use of jp.ossc.nimbus.util.WaitSynchronizeMonitor in project nimbus by nimbus-org.
the class MemorySemaphore method readObject.
/**
* デシリアライズを行う。<p>
*
* @param in デシリアライズの元情報となるストリーム
* @exception IOException 読み込みに失敗した場合
* @exception ClassNotFoundException デシリアライズしようとしたオブジェクトのクラスが見つからない場合
*/
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
in.defaultReadObject();
getMonitor = new WaitSynchronizeMonitor();
usedThreads = new ConcurrentHashMap();
threadTasks = new ConcurrentHashMap();
forceFreeTimer = new Timer(true);
}
Aggregations