📄 jco$poolmanager.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: JCO.java
package com.sap.mw.jco;
import com.sap.mw.jco.util.ObjectList;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
// Referenced classes of package com.sap.mw.jco:
// JCO
public static class JCO$PoolManager
{
protected static class TimeoutChecker
implements Runnable
{
public final void startCheckerFor(JCO.Pool pool)
{
synchronized(pools)
{
if(!pools.contains(pool) && pool.getTimeoutCheckPeriod() > 0L)
{
pool.next_timeout_check = System.currentTimeMillis() + pool.timeout_check_period;
pools.add(pool);
pools.notifyAll();
}
}
}
public final void stopCheckerFor(JCO.Pool pool)
{
synchronized(pools)
{
if(pools.contains(pool))
pools.remove(pool);
}
}
public final void run()
{
JCO.Pool pool_to_check = null;
long to_sleep = 0L;
do
{
long next_check = 0x7fffffffffffffffL;
pool_to_check = null;
synchronized(pools)
{
if(pools.isEmpty())
try
{
pools.wait();
}
catch(InterruptedException ex)
{
JCO.fireTrace(1, "[JAV-LAYER] JCO.TimeoutChecker.run(): wait caused " + ex.toString());
break;
}
for(int i = pools.size(); --i >= 0;)
{
JCO.Pool pool = (JCO.Pool)pools.get(i);
if(pool.next_timeout_check < next_check)
{
pool_to_check = pool;
next_check = pool.next_timeout_check;
}
}
}
to_sleep = next_check - System.currentTimeMillis();
if(pool_to_check == null)
continue;
if(to_sleep > 0L)
{
synchronized(pools)
{
try
{
pools.wait(to_sleep);
}
catch(InterruptedException ex)
{
JCO.fireTrace(1, "[JAV-LAYER] TimeoutChecker.run(): wait caused " + ex.toString());
break;
}
}
continue;
}
if(pools.contains(pool_to_check))
{
pool_to_check.checkForTimeout();
pool_to_check.next_timeout_check = System.currentTimeMillis() + pool_to_check.timeout_check_period;
}
} while(true);
}
private JCO.PoolManager manager;
private boolean is_stopped;
private ObjectList pools;
private Thread ownThread;
public TimeoutChecker(JCO.PoolManager manager)
{
is_stopped = false;
pools = new ObjectList();
ownThread = null;
this.manager = manager;
}
}
protected void startTimeoutChecker()
{
try
{
timeout_checker = new TimeoutChecker(this);
Thread thread = new Thread(timeout_checker);
thread.setContextClassLoader((com.sap.mw.jco.JCO.class).getClassLoader());
thread.setName("JCO.TimeoutChecker");
thread.setDaemon(true);
thread.start();
}
catch(JCO$Exception ex)
{
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager(): Unable to start the TimeoutChecker " + ex.String());
}
}
public static JCO$PoolManager singleton()
{
if(singleton == null)
singleton = createPoolManager();
return singleton;
}
private static JCO$PoolManager createPoolManager()
{
JCO$PoolManager jco$poolmanager;
synchronized(pool_changed_listeners)
{
jco$poolmanager = new JCO$PoolManager();
}
return jco$poolmanager;
}
protected static void registerPoolManager(JCO$PoolManager pool_manager)
{
synchronized(pool_changed_listeners)
{
if(singleton == null)
singleton = pool_manager;
else
throw new nit>(131, "JCO_ERROR_ILLEGAL_ARGUMENT", "PoolManager instance is already registered.");
}
}
public void addPoolChangedListener(istener listener)
{
synchronized(pool_changed_listeners)
{
pool_changed_listeners.addElement(listener);
}
}
public void removePoolChangedListener(istener listener)
{
synchronized(pool_changed_listeners)
{
pool_changed_listeners.removeElement(listener);
}
}
protected void firePoolChanged(JCO$Pool pool)
{
Vector list;
synchronized(pool_changed_listeners)
{
list = (Vector)pool_changed_listeners.clone();
}
istener listener;
for(Enumeration e = list.elements(); e.hasMoreElements(); listener.poolChanged(pool))
listener = (istener)e.nextElement();
}
public void addPool(String pool_name, JCO$Client master, int max_pool_size)
{
nt pool;
synchronized(pools)
{
if(pools.containsKey(pool_name))
throw new JCO$Exception(102, "JCO_ERROR_COMMUNICATION", "A pool with the identifier '" + pool_name + "' already exists");
pool = new JCO$Pool(this, pool_name, master, max_pool_size);
if(max_wait_time != -1L)
pool.aitTime(max_wait_time);
if(connection_timeout != -1L)
pool.ectionTimeout(connection_timeout);
if(timeout_check_period != -1L)
pool.outCheckPeriod(timeout_check_period);
pools.put(pool_name, pool);
if(JCO.trace_level > 0)
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.addPool: \n\t name = " + pool_name + ", \n\t connection = " + master.shKey(true) + ", \n\t pool_size = " + pool.oolSize() + ", \n\t max_wait_time = " + pool.aitTime() + ", \n\t pooled_connection_timeout = " + pool.ectionTimeout() + ", \n\t timeout_check_period = " + pool.outCheckPeriod());
}
firePoolChanged(pool);
}
public String[] getPoolNames()
{
String pool_names[] = new String[pools.size()];
int i = 0;
synchronized(pools)
{
for(Enumeration e = pools.keys(); e.hasMoreElements();)
pool_names[i++] = (String)e.nextElement();
}
return pool_names;
}
public JCO$Pool getPool(String pool_name)
{
return (nt)pools.get(pool_name);
}
public void removePool(String pool_name)
{
if(JCO.trace_level > 0)
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.removePool(\"" + pool_name + "\") ");
pools pool;
synchronized(pools)
{
pool = (JCO$Pool)pools.get(pool_name);
if(pool == null)
return;
pools.remove(pool_name);
}
pool. = null;
timeout_checker.stopCheckerFor(pool);
pool.clear();
firePoolChanged(pool);
}
public JCO$Client getClient(String pool_name)
{
return getClient(pool_name, false);
}
public JCO$Client getClient(String pool_name, boolean reset)
{
JCO$Client client = null;
getClient pool = (JCO$Pool)pools.get(pool_name);
if(pool == null)
{
if(JCO.trace_level > 0)
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.getClient(" + pool_name + ", " + reset + ") Error: application trys to get client from removed or non existent pool.");
return null;
}
if(!pool.ialized)
pool.l();
client = pool.nt(reset);
firePoolChanged(pool);
return client;
}
public void releaseClient(JCO$Client client)
{
if(client == null)
{
if(JCO.trace_level > 2)
JCO.fireTrace(3, "[JAV-LAYER] JCO.PoolManager.releaseClient: Cannot release client equals null \n");
return;
}
if(((JCO$Connection) (client)).ool == null)
{
client.nnect(false);
return;
} else
{
((nnect) (client)).ool.Client(client);
firePoolChanged(((JCO$Connection) (client)).ool);
return;
}
}
public void detachFromPool(JCO$Client client)
{
if(client == null || ((JCO$Connection) (client)).ool == null)
{
StringBuffer to_trace = new StringBuffer("[JAV-LAYER] Cannot detach client equals ");
if(client == null)
to_trace.append("null\n");
else
to_trace.append(client.toString()).append(" from pool equals null\n");
StringWriter buf = new StringWriter();
Throwable t = new Throwable();
t.fillInStackTrace();
t.printStackTrace(new PrintWriter(buf));
to_trace.append(buf.getBuffer());
JCO.fireTrace(3, to_trace.toString());
return;
}
if((((JCO$Connection) (client)).tate & 0x10) == 0)
{
JCO$Exception ex = new JCO$Exception(106, "JCO_ERROR_RESOURCE", "A client isn't allocated from pool cannot be detached." + JCO.CRLF + "Please, use JCO.getClient(String pool) first.");
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.detachFromPool(): " + ex.String());
throw ex;
} else
{
((JCO$Connection) (client)).ool.romPool(client);
client.ool = null;
return;
}
}
/**
* @deprecated Method removeConnection is deprecated
*/
public void removeConnection(ool connection)
{
if(connection == null)
{
JCO.fireTrace(5, "[JAV-LAYER] JCO.PoolManager.removeConnection: warning connection = null");
return;
}
if(connection.ool == null)
JCO.fireTrace(5, "[JAV-LAYER] JCO.PoolManager.removeConnection: warning connection isn't pooled");
if(connection instanceof JCO$Client)
{
((JCO$Connection) ((JCO$Client)connection)).ool.romPool((romPool)connection);
((romPool)connection).ool = null;
((JCO$Client)connection).nnect(true);
} else
{
connection.isconnect();
}
}
public long getTimeoutCheckPeriod()
{
return timeout_check_period;
}
public void setTimeoutCheckPeriod(long timeout_check_period)
{
this.timeout_check_period = timeout_check_period;
}
public long getConnectionTimeout()
{
return connection_timeout;
}
public void setConnectionTimeout(long connection_timeout)
{
this.connection_timeout = connection_timeout;
}
public final long getMaxWaitTime()
{
return max_wait_time;
}
public final void setMaxWaitTime(long max_wait_time)
{
this.max_wait_time = max_wait_time;
}
private static JCO$PoolManager singleton = null;
private static Vector pool_changed_listeners = new Vector();
protected Hashtable pools;
protected TimeoutChecker timeout_checker;
protected long max_wait_time;
protected long connection_timeout;
protected long timeout_check_period;
protected JCO$PoolManager()
{
pools = new Hashtable();
max_wait_time = -1L;
connection_timeout = -1L;
timeout_check_period = -1L;
startTimeoutChecker();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -