Search in sources :

Example 66 with RejectedExecutionException

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.");
        }
    }
}
Also used : IDLEntity(org.omg.CORBA.portable.IDLEntity) EventDescription(alma.acsnc.EventDescription) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 67 with RejectedExecutionException

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;
}
Also used : RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 68 with RejectedExecutionException

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
    }
}
Also used : ProductParsedResult(com.google.zxing.client.result.ProductParsedResult) SpannableString(android.text.SpannableString) URIParsedResult(com.google.zxing.client.result.URIParsedResult) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ISBNParsedResult(com.google.zxing.client.result.ISBNParsedResult)

Example 69 with RejectedExecutionException

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
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.testng.annotations.Test)

Example 70 with RejectedExecutionException

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)")));
}
Also used : InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) PortUnreachableException(java.net.PortUnreachableException) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) SSLException(javax.net.ssl.SSLException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MalformedURLException(java.net.MalformedURLException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) EOFException(java.io.EOFException) InterruptedIOException(java.io.InterruptedIOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SSLException(javax.net.ssl.SSLException) SocketTimeoutException(java.net.SocketTimeoutException) PortUnreachableException(java.net.PortUnreachableException) CertPathValidatorException(java.security.cert.CertPathValidatorException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) CertPathValidatorException(java.security.cert.CertPathValidatorException) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) Test(org.junit.Test)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)246 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)34 Test (org.junit.Test)34 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 Executor (java.util.concurrent.Executor)18 ExecutionException (java.util.concurrent.ExecutionException)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9