📄 jco$pool.java
字号:
client = (t)available.pop();
if(available.isEmpty())
shouldStopTimeoutChecker = true;
current_used++;
} else
if(current_used < max_connections)
{
client = (t)master.clone();
client.pool = this;
current_used++;
}
break;
}
}
}
catch(InterruptedException ex)
{
waiting_threads.remove(Thread.currentThread());
if(waiting_threads.size() == 0)
waiting_threads = null;
JCO.fireTrace(1, "[JAV-LAYER] JCO.Pool.getClient(): wait(" + duration + ") caused " + ex.toString());
throw new tion(106, "JCO_ERROR_RESOURCE", ex.toString());
}
}
}
if(client != null)
{
max_used = Math.max(max_used, current_used);
if(reset && (((ction) (client)).state & 2) != 0)
if(r3_version < 4)
try
{
client.disconnect(true);
}
catch(tion ex)
{
synchronized(available)
{
current_used--;
available.notifyAll();
}
throw ex;
}
else
if(!reset_on_release)
try
{
client.middleware.reset(client);
}
catch(tion ex)
{
JCO.fireTrace(1, "[JAV-LAYER] JCO.Pool.getClient(): Reset caused " + ex.toString());
try
{
client.middleware.disconnect(client);
}
catch(Throwable t) { }
synchronized(available)
{
current_used--;
available.notifyAll();
}
throw ex;
}
try
{
if(client.isValid() && !client.middleware.isAlive(client))
client.disconnect(true);
if((((ction) (client)).state & 1) != 0)
client.connect();
}
catch(tion ex)
{
synchronized(available)
{
current_used--;
available.notifyAll();
}
JCO.fireTrace(1, "[JAV-LAYER] JCO.Pool.getClient(): " + ex.toString());
throw ex;
}
client.state |= 0x10;
if(JCO.trace_level < -10)
{
Throwable throwable = new Throwable();
throwable.fillInStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println("-------------- Trace of where JCO.getClient() was called -----------------");
throwable.printStackTrace(pw);
pw.println("--------------------------------------------------------------------------");
client.stack_trace = sw.toString();
}
} else
{
tion ex = new tion(106, "JCO_ERROR_RESOURCE", "Connection pool " + name + " is exhausted. The current pool size limit is " + max_pool_size + " connections.");
JCO.fireTrace(1, "[JAV-LAYER] JCO.Pool.getClient(): No clients available. " + ex.toString());
throw ex;
}
if(JCO.getTraceLevel() > 1)
JCO.fireTrace(2, "[JAV-LAYER] JCO.Pool.getClient(" + reset + ") returns [" + client.getConnectionHandle() + "] [leave]");
if(shouldStopTimeoutChecker && available.isEmpty() && manager != null && timeout_check_period > 0L)
manager.timeout_checker.stopCheckerFor(this);
return client;
}
protected final void releaseClient(t client)
{
if(JCO.trace_level > 1)
JCO.fireTrace(2, "[JAV-LAYER] JCO.Pool.releaseClient([" + client.getConnectionHandle() + "]) in pool " + getName());
if(client == null)
return;
if(((ction) (client)).pool == null)
{
client.disconnect(false);
return;
}
t clone = null;
synchronized(available)
{
if((((ction) (client)).state & 0x10) == 0)
return;
client.state &= 0xef;
}
try
{
clone = client.hide();
}
catch(tion ex)
{
if(JCO.trace_level > 0)
JCO.fireTrace(1, "[JAV-LAYER] JCO.Pool.releaseClient() concurrent release detected,the client is used by application in an other thread " + ex.toString());
client.state |= 0x10;
throw ex;
}
try
{
if(manager == null)
{
clone.pool = null;
clone.disconnect(false);
clone = null;
} else
if(connection_timeout <= 0L || !clone.isAlive())
{
clone.state = (byte)(((ction) (clone)).state & 0xf0 | 1);
clone.middleware.disconnect(clone);
} else
{
if(t.access._mth100(clone) != null)
{
clone.state |= 0x10;
clone.endAuthorizationTracing();
clone.state &= 0xef;
}
if(reset_on_release && r3_version >= 4)
try
{
clone.middleware.reset(clone);
}
catch(tion ex)
{
if(JCO.trace_level > 0)
JCO.fireTrace(1, "[JAV-LAYER] Pool.releaseClient [" + ((ction) (clone)).rfc_handle + "] failed with " + ex.toString());
clone.middleware.disconnect(clone);
clone = null;
throw ex;
}
}
}
finally
{
synchronized(available)
{
if(clone != null)
{
client = (t)available.push(clone);
if(client != null)
try
{
client.middleware.disconnect(client);
}
catch(tion ex) { }
}
current_used--;
available.notifyAll();
}
if(manager != null && !available.isEmpty() && timeout_check_period > 0L)
manager.timeout_checker.startCheckerFor(this);
}
}
public void detachFromPool(t client)
{
if(client == null || ((ction) (client)).pool == null)
return;
if((((ction) (client)).state & 0x10) == 0)
{
tion ex = new tion(106, "JCO_ERROR_RESOURCE", "A client that is not allocated from pool cannot be detached." + JCO.CRLF + "Please, use JCO.getClient(String pool) first.");
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.detachFromPool(): " + ex.toString());
throw ex;
}
if(((ction) (client)).pool != this)
{
tion ex = new tion(106, "JCO_ERROR_RESOURCE", "A client allocated from pool " + ((ction) (client)).pool.getName() + " cannot be detached from " + getName() + ".");
JCO.fireTrace(1, "[JAV-LAYER] JCO.PoolManager.detachFromPool(): " + ex.toString());
throw ex;
} else
{
current_used--;
client.pool = null;
client.state &= 0xef;
return;
}
}
protected final void checkForTimeout()
{
if(available.isEmpty())
return;
synchronized(available)
{
long now = System.currentTimeMillis();
for(int i = 0; i < available.size(); i++)
{
t conn = (t)available.get(i);
if(now - ((ction) (conn)).last_active_timestamp > connection_timeout)
{
available.remove(conn);
try
{
conn.disconnect(true);
}
catch(tion ex)
{
if(JCO.trace_level > 7)
JCO.fireTrace(8, "[JAV-LAYER] JCO.Pool.CheckforTimeout: disconnect caused " + ex.toString());
}
}
}
}
}
public final int INFINITE = 0x7fffffff;
protected String name;
protected t master;
protected int max_pool_size;
protected int max_connections;
protected long max_wait_time;
protected long connection_timeout;
protected long timeout_check_period;
protected long next_timeout_check;
protected int max_used;
protected int current_used;
protected LimitedList available;
protected ObjectList waiting_threads;
protected anager manager;
protected boolean is_initialized;
protected byte r3_version;
protected boolean reset_on_release;
protected JCO$Pool(anager manager, String name, t master, int max_pool_size)
{
max_wait_time = 30000L;
connection_timeout = 0x927c0L;
timeout_check_period = 60000L;
waiting_threads = null;
is_initialized = false;
r3_version = 4;
reset_on_release = true;
this.manager = manager;
this.name = name;
this.master = (t)master.clone();
this.max_pool_size = max_pool_size;
max_connections = max_pool_size;
available = new LimitedList(max_pool_size);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -