javax.resource.spi.IllegalStateException Java Examples

The following examples show how to use javax.resource.spi.IllegalStateException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Cleanup
 *
 * @throws ResourceException Thrown if an error occurs
 */
@Override
public void cleanup() throws ResourceException {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("cleanup()");
   }

   if (isDestroyed.get()) {
      throw new IllegalStateException("ManagedConnection already destroyed");
   }

   destroyHandles();

   inManagedTx = false;

   inManagedTx = false;

   // I'm recreating the lock object when we return to the pool
   // because it looks too nasty to expect the connection handle
   // to unlock properly in certain race conditions
   // where the dissociation of the managed connection is "random".
   lock = new ReentrantLock();
}
 
Example #2
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void checkTransactionActive() throws JMSException {
   // don't bother looking at the transaction if there's an active XID
   if (!inManagedTx && tm != null) {
      try {
         Transaction tx = tm.getTransaction();
         if (tx != null) {
            int status = tx.getStatus();
            // Only allow states that will actually succeed
            if (status != Status.STATUS_ACTIVE && status != Status.STATUS_PREPARING && status != Status.STATUS_PREPARED && status != Status.STATUS_COMMITTING) {
               throw new javax.jms.IllegalStateException("Transaction " + tx + " not active");
            }
         }
      } catch (SystemException e) {
         JMSException jmsE = new javax.jms.IllegalStateException("Unexpected exception on the Transaction ManagerTransaction");
         jmsE.initCause(e);
         throw jmsE;
      }
   }
}
 
Example #3
Source File: EnversTestValidationResource.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@POST
public String save(String name) {
    try {
        transaction.begin();
        MyAuditedEntity entity = new MyAuditedEntity();
        entity.setName("initial");
        em.persist(entity);
        transaction.commit();

        transaction.begin();
        entity.setName(name);
        em.merge(entity);
        em.flush();
        transaction.commit();

        AuditReader auditReader = AuditReaderFactory.get(em);
        List<Number> revisions = auditReader.getRevisions(MyAuditedEntity.class, entity.getId());
        if (revisions.size() != 2) {
            throw new IllegalStateException(String.format("found {} revisions", revisions.size()));
        }

        MyRevisionEntity revEntity = auditReader.findRevision(MyRevisionEntity.class, revisions.get(0));
        if (revEntity.getListenerValue() == null) {
            throw new IllegalStateException("revision listener failed to update revision entity");
        }

        return "OK";
    } catch (Exception exception) {
        return exception.getMessage();
    }
}
 
Example #4
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Get a connection
 *
 * @param subject       The security subject
 * @param cxRequestInfo The request info
 * @return The connection
 * @throws ResourceException Thrown if an error occurs
 */
@Override
public synchronized Object getConnection(final Subject subject,
                                         final ConnectionRequestInfo cxRequestInfo) throws ResourceException {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("getConnection(" + subject + ", " + cxRequestInfo + ")");
   }

   // Check user first
   ActiveMQRACredential credential = ActiveMQRACredential.getCredential(mcf, subject, cxRequestInfo);

   // Null users are allowed!
   if (userName != null && !userName.equals(credential.getUserName())) {
      throw new SecurityException("Password credentials not the same, reauthentication not allowed");
   }

   if (userName == null && credential.getUserName() != null) {
      throw new SecurityException("Password credentials not the same, reauthentication not allowed");
   }

   if (isDestroyed.get()) {
      throw new IllegalStateException("The managed connection is already destroyed");
   }

   ActiveMQRASession session = new ActiveMQRASession(this, (ActiveMQRAConnectionRequestInfo) cxRequestInfo);
   handles.add(session);
   return session;
}
 
Example #5
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Move a handler from one mc to this one.
 *
 * @param obj An object of type ActiveMQSession.
 * @throws ResourceException     Failed to associate connection.
 * @throws IllegalStateException ManagedConnection in an illegal state.
 */
@Override
public void associateConnection(final Object obj) throws ResourceException {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("associateConnection(" + obj + ")");
   }

   if (!isDestroyed.get() && obj instanceof ActiveMQRASession) {
      ActiveMQRASession h = (ActiveMQRASession) obj;
      h.setManagedConnection(this);
      handles.add(h);
   } else {
      throw new IllegalStateException("ManagedConnection in an illegal state");
   }
}
 
Example #6
Source File: ActiveMQRAManagedConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Get the meta data for the connection.
 *
 * @return The meta data for the connection.
 * @throws ResourceException     Thrown if the operation fails.
 * @throws IllegalStateException Thrown if the managed connection already is destroyed.
 */
@Override
public ManagedConnectionMetaData getMetaData() throws ResourceException {
   if (logger.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("getMetaData()");
   }

   if (isDestroyed.get()) {
      throw new IllegalStateException("The managed connection is already destroyed");
   }

   return new ActiveMQRAMetaData(this);
}
 
Example #7
Source File: RouteBuilderF.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void configure() throws Exception {

    log.info("Configure: {}", getClass().getName());

    final CountDownLatch startLatch = new CountDownLatch(1);

    // verify that a component can be added manually
    getContext().addComponent("quartz", new QuartzComponent() {
        @Override
        public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
            super.onCamelContextStarted(context, alreadyStarted);
            startLatch.countDown();
        }
    });

    from("quartz://mytimer?trigger.repeatCount=3&trigger.repeatInterval=100&fireNow=true")
    .process(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            log.info("Process: {}", exchange);
            if (startLatch.getCount() > 0)
                throw new IllegalStateException("onCamelContextStarted not called");
        }
    })
    .to(MOCK_RESULT_URI);
}