Package javax.resource.spi.work

Examples of javax.resource.spi.work.ExecutionContext


   }

   public void scheduleWork(Work work, long startTimeout, ExecutionContext ctx, WorkListener listener) throws WorkException
   {
      if (ctx == null)
         ctx = new ExecutionContext();
      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_NONE, startTimeout, ctx, listener);
      importWork(wrapper);
      executeWork(wrapper);
      if (wrapper.getWorkException() != null)
         throw wrapper.getWorkException();
View Full Code Here


    * @param wrapper the work wrapper
    * @throws WorkException for any error
    */
   protected void importWork(WorkWrapper wrapper) throws WorkException
   {
      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            long timeout = ctx.getTransactionTimeout();
            xaTerminator.registerWork(wrapper.getWork(), xid, timeout);
         }
      }
   }
View Full Code Here

    * @param wrapper the work wrapper
    * @throws WorkException for any error
    */
   protected void startWork(WorkWrapper wrapper) throws WorkException
   {
      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.startWork(wrapper.getWork(), xid);
         }
      }
View Full Code Here

    * @param wrapper the work wrapper
    * @throws WorkException for any error
    */
   protected void endWork(WorkWrapper wrapper)
   {
      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.endWork(wrapper.getWork(), xid);
         }
      }
View Full Code Here

    * @param wrapper the work wrapper
    * @throws WorkException for any error
    */
   protected void cancelWork(WorkWrapper wrapper)
   {
      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.cancelWork(wrapper.getWork(), xid);
         }
      }
View Full Code Here

         WorkEvent event = new WorkEvent(workManager, WorkEvent.WORK_STARTED, work, null, duration);
         workListener.workStarted(event);
      }

      // Transaction setup
      ExecutionContext ctx = getWorkContext(TransactionContext.class);
      if (ctx == null)
      {
         ctx = getExecutionContext();
      }
     
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            //JBAS-4002 base value is in seconds as per the API, here we convert to millis
            long timeout = (ctx.getTransactionTimeout() * 1000);
            workManager.getXATerminator().registerWork(work, xid, timeout);
         }
      }

      // Security setup
      javax.resource.spi.work.SecurityContext securityContext =
         getWorkContext(javax.resource.spi.work.SecurityContext.class);
      if (securityContext != null && workManager.getCallbackSecurity() != null)
      {
         if (trace)
            log.tracef("Setting security context: %s", securityContext);

         try
         {
            // Security context
            org.jboss.security.SecurityContext sc = null;

            // Setup callbacks
            CallbackHandler cbh = new JASPICallbackHandler();

            // Subjects for execution environment
            Subject executionSubject = null;
            Subject serviceSubject = null;
        
            if (trace)
               log.tracef("Callback security: %s", workManager.getCallbackSecurity());

            if (SecurityContextAssociation.getSecurityContext() == null ||
                workManager.getCallbackSecurity().getDomain() != null)
            {
               String scDomain = workManager.getCallbackSecurity().getDomain();

               if (trace)
                  log.tracef("Creating security context: %s", scDomain);

               if (scDomain == null || scDomain.trim().equals(""))
               {
                  fireWorkContextSetupFailed(ctx);
                  throw new WorkException(bundle.securityContextSetupFailedSinceCallbackSecurityDomainWasEmpty());
               }

               sc = SecurityContextFactory.createSecurityContext(scDomain);
               SecurityContextAssociation.setSecurityContext(sc);
            }
            else
            {
               sc = SecurityContextAssociation.getSecurityContext();

               if (trace)
                  log.tracef("Using security context: %s", sc);
            }

            executionSubject = sc.getSubjectInfo().getAuthenticatedSubject();

            if (executionSubject == null)
            {
               if (trace)
                  log.tracef("Creating empty subject");

               executionSubject = new Subject();
            }

            // Resource adapter callback
            securityContext.setupSecurityContext(cbh, executionSubject, serviceSubject);

            List<Callback> callbacks = new ArrayList<Callback>();
            if (workManager.getCallbackSecurity().isMappingRequired())
            {
               // JCA 1.6: 16.4.4
            }

            if (workManager.getCallbackSecurity().getDefaultPrincipal() != null)
            {
               Principal defaultPrincipal = workManager.getCallbackSecurity().getDefaultPrincipal();
               CallerPrincipalCallback cpc =
                  new CallerPrincipalCallback(executionSubject, defaultPrincipal);

               callbacks.add(cpc);
            }

            if (workManager.getCallbackSecurity().getDefaultGroups() != null)
            {
               String[] defaultGroups = workManager.getCallbackSecurity().getDefaultGroups();
               GroupPrincipalCallback gpc =
                  new GroupPrincipalCallback(executionSubject, defaultGroups);

               callbacks.add(gpc);
            }

            if (callbacks.size() > 0)
            {
               Callback[] cb = new Callback[callbacks.size()];
               cbh.handle(callbacks.toArray(cb));
            }

            if (trace)
               log.tracef("Setting authenticated subject (%s) on security context (%s)", executionSubject, sc);

            // Set the authenticated subject
            sc.getSubjectInfo().setAuthenticatedSubject(executionSubject);
         }
         catch (Throwable t)
         {
            log.securityContextSetupFailed(t.getMessage(), t);
            fireWorkContextSetupFailed(ctx);
            throw new WorkException(bundle.securityContextSetupFailed(t.getMessage()), t);
         }
      }
      else if (securityContext != null && workManager.getCallbackSecurity() == null)
      {
         log.securityContextSetupFailedCallbackSecurityNull();
         fireWorkContextSetupFailed(ctx);
         throw new WorkException(bundle.securityContextSetupFailedSinceCallbackSecurityWasNull());
      }
  
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            workManager.getXATerminator().startWork(work, xid);
         }
      }
View Full Code Here

      if (trace)
      {
         log.trace("Ending work " + this)
      }

      ExecutionContext ctx = getWorkContext(TransactionContext.class);
      if (ctx == null)
      {
         ctx = getExecutionContext();
      }

      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            workManager.getXATerminator().endWork(work, xid);
         }
      }
View Full Code Here

   protected void cancel()
   {
      if (trace)
         log.trace("Cancel work " + this)

      ExecutionContext ctx = getWorkContext(TransactionContext.class);
      if (ctx == null)
      {
         ctx = getExecutionContext();
      }

      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            workManager.getXATerminator().cancelWork(work, xid);
         }
      }
View Full Code Here

            workListener.workAccepted(event);
         }

         if (execContext == null)
         {
            execContext = new ExecutionContext()
         }

         final CountDownLatch completedLatch = new CountDownLatch(1);

         wrapper = new WorkWrapper(this, work, execContext, workListener, null, completedLatch,
View Full Code Here

            workListener.workAccepted(event);
         }

         if (execContext == null)
         {
            execContext = new ExecutionContext()
         }

         final CountDownLatch startedLatch = new CountDownLatch(1);

         wrapper = new WorkWrapper(this, work, execContext, workListener, startedLatch, null,
View Full Code Here

TOP

Related Classes of javax.resource.spi.work.ExecutionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.