List of usage examples for javax.jms IllegalStateException IllegalStateException
public IllegalStateException(String reason)
From source file:com.github.mrstampy.gameboot.otp.OtpTestConfiguration.java
private InputStream getResource(String name) throws Exception { ClassPathResource r = new ClassPathResource(name); if (!r.exists()) throw new IllegalStateException("No " + name + " on the classpath"); return r.getInputStream(); }
From source file:com.amazon.sqs.javamessaging.SQSConnection.java
/** * Checks if the connection close is in-progress or already completed. * //from w w w . j a va 2 s. c o m * @throws IllegalStateException * If the connection close is in-progress or already completed. */ public void checkClosing() throws IllegalStateException { if (closing) { throw new IllegalStateException("Connection is closed or closing"); } }
From source file:com.amazon.sqs.javamessaging.SQSConnection.java
/** * Checks if the connection close is already completed. * //from ww w. j av a 2 s.c o m * @throws IllegalStateException * If the connection close is already completed. */ public void checkClosed() throws IllegalStateException { if (closed) { throw new IllegalStateException("Connection is closed"); } }
From source file:com.amazon.sqs.javamessaging.SQSMessageConsumer.java
private void checkClosed() throws IllegalStateException { if (closed) { throw new IllegalStateException("Consumer is closed"); }//from w w w . j a v a2 s .c om }
From source file:com.amazon.sqs.javamessaging.SQSConnection.java
/** * Stops a connection's delivery of incoming messages. A call to * <code>stop</code> on a connection that has already been stopped is * ignored./*from www. j av a 2s .c o m*/ * <P> * This will not return until all the sessions stop internally, which blocks * until receives and/or message listeners in progress have completed. While * these message listeners are completing, they must have the full services * of the connection available to them. * <P> * A call to stop must not return until delivery of messages has paused. * This means that a client can rely on the fact that none of its message * listeners will be called and that all threads of control waiting for * receive calls to return will not return with a message until the * connection is restarted. The receive timers for a stopped connection * continue to advance, so receives may time out while the connection is * stopped. * <P> * A message listener must not attempt to stop its own connection; otherwise * throws a IllegalStateException. * * @throws IllegalStateException * If called by a message listener on its own * <code>Connection</code>. * @throws JMSException * On internal error or called if close is in progress. */ @Override public void stop() throws JMSException { checkClosed(); if (!running) { return; } actionOnConnectionTaken = true; if (SQSSession.SESSION_THREAD_FACTORY.wasThreadCreatedWithThisThreadGroup(Thread.currentThread())) { throw new IllegalStateException( "MessageListener must not attempt to stop its own Connection to prevent potential deadlock issues"); } synchronized (stateLock) { checkClosing(); if (running) { try { for (Session session : sessions) { SQSSession sqsSession = (SQSSession) session; /** * Session stop call blocks until receives and/or * message listeners in progress have completed. */ sqsSession.stop(); } } finally { running = false; } } } }
From source file:com.amazon.sqs.javamessaging.SQSSession.java
/** * Closes the session./*from w w w.j a v a2s . c om*/ * <P> * This will not return until all the message consumers and producers close * internally, which blocks until receives and/or message listeners in * progress have completed. A blocked message consumer receive call returns * null when this session is closed. * <P> * Since consumer prefetch threads use SQS long-poll feature with 20 seconds * timeout, closing each consumer prefetch thread can take up to 20 seconds, * which in-turn will impact the time on session close. * <P> * This method is safe for concurrent use. * <P> * A message listener must not attempt to close its own session; otherwise * throws a IllegalStateException. * <P> * Invoking any other session method on a closed session must throw a * <code>IllegalStateException</code>. * * @throws IllegalStateException * If called by a message listener on its own * <code>Session</code>. * @throws JMSException * On internal error. */ @Override public void close() throws JMSException { if (closed) { return; } /** * A MessageListener must not attempt to close its own Session as * this would lead to deadlock */ if (isActiveCallbackSessionThread()) { throw new IllegalStateException( "MessageListener must not attempt to close its own Session to prevent potential deadlock issues"); } doClose(); }
From source file:com.amazon.sqs.javamessaging.SQSConnection.java
/** * Closes the connection.// ww w . j av a 2 s. co m * <P> * This will not return until all the sessions close internally, which * blocks until receives and/or message listeners in progress have * completed. * <P> * The receives may return with a message or with null, depending on whether * there was a message available at the time of the close. If one or more of * the connection's sessions' message listeners is processing a message at * the time when connection close is invoked, all the facilities of the * connection and its sessions must remain available to those listeners * until they return control to the JMS provider. * <P> * A message listener must not attempt to close its own connection; * otherwise throws a IllegalStateException. * * @throws IllegalStateException * If called by a message listener on its own * <code>Connection</code>. * @throws JMSException * On internal error. */ @Override public void close() throws JMSException { if (closed) { return; } /** * A message listener must not attempt to close its own connection as * this would lead to deadlock. */ if (SQSSession.SESSION_THREAD_FACTORY.wasThreadCreatedWithThisThreadGroup(Thread.currentThread())) { throw new IllegalStateException( "MessageListener must not attempt to close its own Connection to prevent potential deadlock issues"); } boolean shouldClose = false; synchronized (stateLock) { if (!closing) { shouldClose = true; closing = true; } } if (shouldClose) { synchronized (stateLock) { try { for (Session session : sessions) { SQSSession sqsSession = (SQSSession) session; sqsSession.close(); } sessions.clear(); } finally { closed = true; stateLock.notifyAll(); } } } /** Blocks until closing of the connection completes */ else { synchronized (stateLock) { while (!closed) { try { stateLock.wait(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting the session to close.", e); } } } } }
From source file:com.amazon.sqs.javamessaging.SQSMessageProducer.java
void checkClosed() throws IllegalStateException { if (closed.get()) { throw new IllegalStateException("The producer is closed."); }/*w w w . j a v a 2s .c o m*/ }
From source file:com.amazon.sqs.javamessaging.SQSConnection.java
/** * Sets the client identifier for this connection. * <P>/* ww w.j a va2 s . c om*/ * Does not verify uniqueness of client ID, so does not detect if another * connection is already using the same client ID * * @param clientID * The client identifier * @throws JMSException * If the connection is being closed * @throws InvalidClientIDException * If empty or null client ID is used * @throws IllegalStateException * If the client ID is already set or attempted to set after an * action on the connection already took place */ @Override public void setClientID(String clientID) throws JMSException { checkClosing(); if (clientID == null || clientID.isEmpty()) { throw new InvalidClientIDException("ClientID is empty"); } if (this.clientID != null) { throw new IllegalStateException("ClientID is already set"); } if (actionOnConnectionTaken) { throw new IllegalStateException("Client ID cannot be set after any action on the connection is taken"); } this.clientID = clientID; }
From source file:com.amazon.sqs.javamessaging.SQSSession.java
void startingCallback(SQSMessageConsumer consumer) throws InterruptedException, JMSException { if (closed) { return;// ww w. jav a 2 s. com } synchronized (stateLock) { if (activeConsumerInCallback != null) { throw new IllegalStateException("Callback already in progress"); } assert activeCallbackSessionThread == null; while (!running && !closing) { try { stateLock.wait(); } catch (InterruptedException e) { LOG.warn("Interrupted while waiting on session start. Continue to wait...", e); } } checkClosing(); activeConsumerInCallback = consumer; activeCallbackSessionThread = Thread.currentThread(); } }