use of java.util.concurrent.RejectedExecutionException in project ACS by ACS-Community.
the class Consumer method push_structured_event.
/**
* As of ACS 3.0, override {@link #processEvent(Object)} instead of this
* CORBA method. push_structured_event is what is called each time an event
* is received. <b>Do not call it from your code!</b>
*
* @param structuredEvent
* The structured event sent by a supplier subclass.
* @throws org.omg.CosEventComm.Disconnected
*/
public void push_structured_event(StructuredEvent structuredEvent) throws org.omg.CosEventComm.Disconnected {
// time to get the event description
final EventDescription eDescrip = EventDescriptionHelper.extract(structuredEvent.remainder_of_body);
Object convertedAny = m_anyAide.complexAnyToObject(structuredEvent.filterable_data[0].value);
IDLEntity struct = null;
try {
struct = (IDLEntity) convertedAny;
if (isTraceEventsEnabled) {
m_logger.log(Level.INFO, "Channel:" + m_channelName + ", Publisher:" + eDescrip.name + ", Event Type:" + structuredEvent.header.fixed_header.event_type.type_name);
}
} catch (ClassCastException ex) {
if (isTraceEventsEnabled && convertedAny != null) {
m_logger.log(Level.INFO, "Channel:" + m_channelName + ", Publisher:" + eDescrip.name + ", Event Type:" + structuredEvent.header.fixed_header.event_type.type_name + ". Failed to convert event data of type '" + convertedAny.getClass().getName() + "' which is not derived from an IDL-defined struct.");
}
}
if (struct != null) {
// process the extracted data in a separate thread
final IDLEntity structToProcess = struct;
// to avoid unnecessary scary logs, we tolerate previous events up to half the queue size
boolean isReceiverBusyWithPreviousEvent = (eventHandlingExecutor.getQueue().size() > EVENT_QUEUE_CAPACITY / 2);
// m_logger.info("Queue size: " + eventHandlingExecutor.getQueue().size());
boolean thisEventDiscarded = false;
try {
eventHandlingExecutor.execute(new Runnable() {
public void run() {
// here we call processEvent from the worker thread
processEvent(structToProcess, eDescrip);
}
});
} catch (RejectedExecutionException ex) {
// receivers have been too slow, queue is full, will drop data.
thisEventDiscarded = true;
numEventsDiscarded++;
}
if ((thisEventDiscarded || isReceiverBusyWithPreviousEvent) && receiverTooSlowLogRepeatGuard.checkAndIncrement()) {
LOG_NC_ReceiverTooSlow.log(m_logger, m_clientName, numEventsDiscarded, struct.getClass().getName(), m_channelName, getNotificationFactoryName());
numEventsDiscarded = 0;
}
} else {
// Should compare this with specs and C++ impl
if (isTraceEventsEnabled) {
m_logger.info("Will ignore event of type " + structuredEvent.header.fixed_header.event_type.type_name + " which has no data attached.");
}
}
}
use of java.util.concurrent.RejectedExecutionException in project atmosphere by Atmosphere.
the class DefaultBroadcaster method addAtmosphereResource.
@Override
public Broadcaster addAtmosphereResource(AtmosphereResource r) {
try {
if (destroyed.get()) {
logger.debug(DESTROYED, getID(), "addAtmosphereResource(AtmosphereResource r");
return this;
}
start();
if (scope == SCOPE.REQUEST && requestScoped.getAndSet(true)) {
throw new IllegalStateException("Broadcaster " + this + " cannot be used as its scope is set to REQUEST");
}
// To avoid excessive synchronization, we allow resources.size() to get larger that maxSuspendResource
if (maxSuspendResource.get() > 0 && resources.size() >= maxSuspendResource.get()) {
// Resume the first in.
if (policy == POLICY.FIFO) {
// TODO handle null return from poll()
AtmosphereResource resource = resources.poll();
try {
logger.warn("Too many resource. Forcing resume of {} ", resource.uuid());
resource.resume();
} catch (Throwable t) {
logger.warn("failed to resume resource {} ", resource, t);
}
} else if (policy == POLICY.REJECT) {
throw new RejectedExecutionException(String.format("Maximum suspended AtmosphereResources %s", maxSuspendResource));
}
}
if (!r.isSuspended()) {
logger.warn("AtmosphereResource {} is not suspended. If cached messages exists, this may cause unexpected situation. Suspend first", r.uuid());
}
if (!backwardCompatible && resources.contains(r)) {
boolean duplicate = r.transport() != AtmosphereResource.TRANSPORT.WEBSOCKET || AtmosphereResourceImpl.class.cast(r).getRequest(false).getAttribute(INJECTED_ATMOSPHERE_RESOURCE) != null;
if (duplicate) {
AtmosphereResourceImpl dup = (AtmosphereResourceImpl) config.resourcesFactory().find(r.uuid());
if (dup != null && dup != r) {
if (!dup.isPendingClose()) {
logger.warn("Duplicate resource {}. Could be caused by a dead connection not detected by your server. Replacing the old one with the fresh one", r.uuid());
} else {
logger.debug("Not yet closed resource still active {}", r.uuid());
}
AtmosphereResourceImpl.class.cast(dup).dirtyClose();
} else {
logger.debug("Duplicate resource {}", r.uuid());
return this;
}
} else {
logger.debug("Duplicate resource {}", r.uuid());
return this;
}
}
// Only synchronize if we have a valid BroadcasterCache
if (!bc.getBroadcasterCache().getClass().equals(BroadcasterCache.DEFAULT.getClass())) {
// In case we are adding messages to the cache, we need to make sure the operation is done before.
synchronized (resources) {
cacheAndSuspend(r);
}
} else {
cacheAndSuspend(r);
}
} finally {
// OK reset
if (!resources.isEmpty()) {
synchronized (awaitBarrier) {
awaitBarrier.notifyAll();
}
}
}
return this;
}
use of java.util.concurrent.RejectedExecutionException in project zxing by zxing.
the class SupplementalInfoRetriever method maybeInvokeRetrieval.
public static void maybeInvokeRetrieval(TextView textView, ParsedResult result, HistoryManager historyManager, Context context) {
try {
if (result instanceof URIParsedResult) {
SupplementalInfoRetriever uriRetriever = new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context);
uriRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
SupplementalInfoRetriever titleRetriever = new TitleRetriever(textView, (URIParsedResult) result, historyManager);
titleRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (result instanceof ProductParsedResult) {
ProductParsedResult productParsedResult = (ProductParsedResult) result;
String productID = productParsedResult.getProductID();
SupplementalInfoRetriever productRetriever = new ProductResultInfoRetriever(textView, productID, historyManager, context);
productRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (result instanceof ISBNParsedResult) {
String isbn = ((ISBNParsedResult) result).getISBN();
SupplementalInfoRetriever productInfoRetriever = new ProductResultInfoRetriever(textView, isbn, historyManager, context);
productInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
SupplementalInfoRetriever bookInfoRetriever = new BookResultInfoRetriever(textView, isbn, historyManager, context);
bookInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} catch (RejectedExecutionException ree) {
// do nothing
}
}
use of java.util.concurrent.RejectedExecutionException in project pulsar by yahoo.
the class ManagedLedgerTest method deleteWithErrors2.
@Test(timeOut = 20000)
public void deleteWithErrors2() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger");
ledger.addEntry("dummy-entry-1".getBytes(Encoding));
stopZooKeeper();
try {
ledger.delete();
fail("should have failed");
} catch (ManagedLedgerException e) {
// ok
} catch (RejectedExecutionException e) {
// ok
}
}
use of java.util.concurrent.RejectedExecutionException in project mobile-center-sdk-android by Microsoft.
the class HttpUtilsAndroidTest method isRecoverableErrorTest.
@Test
public void isRecoverableErrorTest() {
assertTrue(isRecoverableError(new EOFException()));
assertTrue(isRecoverableError(new InterruptedIOException()));
assertTrue(isRecoverableError(new SocketTimeoutException()));
assertTrue(isRecoverableError(new SocketException()));
assertTrue(isRecoverableError(new PortUnreachableException()));
assertTrue(isRecoverableError(new UnknownHostException()));
assertTrue(isRecoverableError(new RejectedExecutionException()));
assertFalse(isRecoverableError(new MalformedURLException()));
assertFalse(isRecoverableError(new IOException()));
assertTrue(isRecoverableError(new IOException(new EOFException())));
assertFalse(isRecoverableError(new IOException(new Exception())));
for (int i = 0; i <= 4; i++) assertTrue(isRecoverableError(new HttpException(500 + i)));
for (int i = 0; i <= 6; i++) assertFalse(isRecoverableError(new HttpException(400 + i)));
assertTrue(isRecoverableError(new HttpException(408)));
assertFalse(isRecoverableError(new HttpException(413)));
assertTrue(isRecoverableError(new HttpException(429)));
assertTrue(isRecoverableError(new SSLException("Write error: ssl=0x59c28f90: I/O error during system call, Connection timed out")));
assertFalse(isRecoverableError(new SSLHandshakeException("java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.")));
assertFalse(isRecoverableError(new SSLException(null, new CertPathValidatorException("Trust anchor for certification path not found."))));
assertFalse(isRecoverableError(new SSLException("java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty")));
assertTrue(isRecoverableError(new SSLException("Read error: ssl=0x9dd07200: I/O error during system call, Connection reset by peer")));
assertTrue(isRecoverableError(new SSLException("SSL handshake aborted: ssl=0x1cc160: I/O error during system call, Connection reset by peer")));
assertTrue(isRecoverableError(new SSLHandshakeException("javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x870c918: Failure in SSL library, usually a protocol error\nerror:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:658 0xb7c393a1:0x00000000)")));
}
Aggregations