use of java.util.concurrent.RejectedExecutionException in project openhab1-addons by openhab.
the class RRD4jService method getDB.
protected synchronized RrdDb getDB(String alias) {
RrdDb db = null;
File file = new File(DB_FOLDER + File.separator + alias + ".rrd");
try {
if (file.exists()) {
// recreate the RrdDb instance from the file
db = new RrdDb(file.getAbsolutePath());
} else {
File folder = new File(DB_FOLDER);
if (!folder.exists()) {
folder.mkdirs();
}
// create a new database file
// db = new RrdDb(getRrdDef(function, file));
db = new RrdDb(getRrdDef(alias, file));
}
} catch (IOException e) {
logger.error("Could not create rrd4j database file '{}': {}", file.getAbsolutePath(), e.getMessage());
} catch (RejectedExecutionException e) {
// this happens if the system is shut down
logger.debug("Could not create rrd4j database file '{}': {}", file.getAbsolutePath(), e.getMessage());
}
return db;
}
use of java.util.concurrent.RejectedExecutionException in project voltdb by VoltDB.
the class InternalClientResponseAdapter method createTransaction.
public boolean createTransaction(final InternalAdapterTaskAttributes kattrs, final String procName, final Procedure catProc, final ProcedureCallback proccb, final InternalConnectionStatsCollector statsCollector, final StoredProcedureInvocation task, final AuthSystem.AuthUser user, final int partition, final boolean ntPriority, final Function<Integer, Boolean> backPressurePredicate) {
if (!m_partitionExecutor.containsKey(partition)) {
m_partitionExecutor.putIfAbsent(partition, CoreUtils.getSingleThreadExecutor("InternalHandlerExecutor - " + partition));
}
if (backPressurePredicate != null) {
try {
do {
if (m_permits.tryAcquire(BACK_PRESSURE_WAIT_TIME, MILLISECONDS)) {
break;
}
} while (backPressurePredicate.apply(partition));
} catch (InterruptedException e) {
}
}
final InvocationDispatcher dispatcher = getClientInterface().getDispatcher();
ExecutorService executor = m_partitionExecutor.get(partition);
try {
executor.submit(new Runnable() {
@Override
public void run() {
if (!m_internalConnectionIds.containsKey(kattrs.getName())) {
m_internalConnectionIds.putIfAbsent(kattrs.getName(), VoltProtocolHandler.getNextConnectionId());
}
submitTransaction();
}
public boolean submitTransaction() {
final long handle = nextHandle();
task.setClientHandle(handle);
final InternalCallback cb = new InternalCallback(kattrs, catProc, task, procName, partition, proccb, statsCollector, user, handle);
m_callbacks.put(handle, cb);
ClientResponseImpl r = dispatcher.dispatch(task, kattrs, InternalClientResponseAdapter.this, user, null, ntPriority);
if (r != null) {
try {
cb.handleResponse(r);
} catch (Exception e) {
m_logger.error("failed to process dispatch response " + r.getStatusString(), e);
} finally {
m_callbacks.remove(handle);
m_permits.release();
}
return r.getStatus() == ClientResponse.SUCCESS;
}
return true;
}
});
} catch (RejectedExecutionException ex) {
m_logger.error("Failed to submit transaction to the partition queue.", ex);
m_permits.release();
return false;
}
return true;
}
use of java.util.concurrent.RejectedExecutionException in project voltdb by VoltDB.
the class InternalClientResponseAdapter method enqueue.
@Override
public void enqueue(final ByteBuffer b) {
final ClientResponseImpl resp = new ClientResponseImpl();
b.position(4);
try {
resp.initFromBuffer(b);
} catch (IOException ex) {
VoltDB.crashLocalVoltDB("enqueue() in InternalClientResponseAdapter throw an exception", true, ex);
}
final Callback callback = m_callbacks.get(resp.getClientHandle());
if (callback == null) {
throw new IllegalStateException("Callback was null?");
}
if (!m_partitionExecutor.containsKey(callback.getPartitionId())) {
m_logger.error("Invalid partition response recieved for sending internal client response.");
return;
}
ExecutorService executor = m_partitionExecutor.get(callback.getPartitionId());
try {
executor.submit(new Runnable() {
@Override
public void run() {
handle();
}
public void handle() {
try {
callback.handleResponse(resp);
} catch (Exception ex) {
m_logger.error("Failed to process callback.", ex);
} finally {
m_callbacks.remove(resp.getClientHandle());
m_permits.release();
}
}
});
} catch (RejectedExecutionException ex) {
m_logger.error("Failed to submit callback to the response processing queue.", ex);
}
}
use of java.util.concurrent.RejectedExecutionException in project voltdb by VoltDB.
the class ForkJoinPool method fullExternalPush.
/**
* Full version of externalPush. This method is called, among
* other times, upon the first submission of the first task to the
* pool, so must perform secondary initialization. It also
* detects first submission by an external thread by looking up
* its ThreadLocal, and creates a new shared queue if the one at
* index if empty or contended. The plock lock body must be
* exception-free (so no try/finally) so we optimistically
* allocate new queues outside the lock and throw them away if
* (very rarely) not needed.
*
* Secondary initialization occurs when plock is zero, to create
* workQueue array and set plock to a valid value. This lock body
* must also be exception-free. Because the plock seq value can
* eventually wrap around zero, this method harmlessly fails to
* reinitialize if workQueues exists, while still advancing plock.
*/
private void fullExternalPush(ForkJoinTask<?> task) {
// random index seed
int r = 0;
for (int[] z = submitters.get(); ; ) {
WorkQueue[] ws;
WorkQueue q;
int ps, m, k;
if (z == null) {
if (U.compareAndSwapInt(this, INDEXSEED, r = indexSeed, r += SEED_INCREMENT) && r != 0)
submitters.set(z = new int[] { r });
} else if (r == 0) {
// move to a different index
r = z[0];
// same xorshift as WorkQueues
r ^= r << 13;
r ^= r >>> 17;
z[0] = r ^= (r << 5);
}
if ((ps = plock) < 0)
throw new RejectedExecutionException();
else if (ps == 0 || (ws = workQueues) == null || (m = ws.length - 1) < 0) {
// initialize workQueues
// find power of two table size
int p = parallelism;
// ensure at least 2 slots
int n = (p > 1) ? p - 1 : 1;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;
n = (n + 1) << 1;
WorkQueue[] nws = ((ws = workQueues) == null || ws.length == 0 ? new WorkQueue[n] : null);
if (((ps = plock) & PL_LOCK) != 0 || !U.compareAndSwapInt(this, PLOCK, ps, ps += PL_LOCK))
ps = acquirePlock();
if (((ws = workQueues) == null || ws.length == 0) && nws != null)
workQueues = nws;
int nps = (ps & SHUTDOWN) | ((ps + PL_LOCK) & ~SHUTDOWN);
if (!U.compareAndSwapInt(this, PLOCK, ps, nps))
releasePlock(nps);
} else if ((q = ws[k = r & m & SQMASK]) != null) {
if (q.qlock == 0 && U.compareAndSwapInt(q, QLOCK, 0, 1)) {
ForkJoinTask<?>[] a = q.array;
int s = q.top;
boolean submitted = false;
try {
// locked version of push
if ((a != null && a.length > s + 1 - q.base) || (a = q.growArray()) != null) {
// must presize
int j = (((a.length - 1) & s) << ASHIFT) + ABASE;
U.putOrderedObject(a, j, task);
q.top = s + 1;
submitted = true;
}
} finally {
// unlock
q.qlock = 0;
}
if (submitted) {
signalWork(ws, q);
return;
}
}
// move on failure
r = 0;
} else if (((ps = plock) & PL_LOCK) == 0) {
// create new queue
q = new WorkQueue(this, null, SHARED_QUEUE, r);
q.poolIndex = (short) k;
if (((ps = plock) & PL_LOCK) != 0 || !U.compareAndSwapInt(this, PLOCK, ps, ps += PL_LOCK))
ps = acquirePlock();
if ((ws = workQueues) != null && k < ws.length && ws[k] == null)
ws[k] = q;
int nps = (ps & SHUTDOWN) | ((ps + PL_LOCK) & ~SHUTDOWN);
if (!U.compareAndSwapInt(this, PLOCK, ps, nps))
releasePlock(nps);
} else
r = 0;
}
}
use of java.util.concurrent.RejectedExecutionException in project voltdb by VoltDB.
the class LeaderAppointer method acceptPromotion.
@Override
public void acceptPromotion() throws InterruptedException, ExecutionException {
final SettableFuture<Object> blocker = SettableFuture.create();
try {
m_es.submit(new Runnable() {
@Override
public void run() {
try {
acceptPromotionImpl(blocker);
} catch (Throwable t) {
blocker.setException(t);
}
}
});
blocker.get();
} catch (RejectedExecutionException e) {
if (m_es.isShutdown())
return;
throw new RejectedExecutionException(e);
}
}
Aggregations