Examples of InstancePool


Examples of org.jboss.ejb.InstancePool

  
   public Object invoke(Invocation mi)
   throws Exception
   {
      InstanceCache cache = container.getInstanceCache();
      InstancePool pool = container.getInstancePool();
      Object methodID = mi.getId();
      EnterpriseContext ctx = null;
     
      BeanLock lock = container.getLockManager().getLock(methodID);
      boolean callerRunAsIdentityPresent = SecurityActions.peekRunAsIdentity() != null;
      boolean pushSecurityContext = SecurityActions.getSecurityContext() == null;
      try
      {
         /* The security context must be established before the cache
         lookup because the activation of a session should have the caller's
         security context as ejbActivate is allowed to call other secured
         resources. Since the pm makes the ejbActivate call, we need to
         set the caller's security context. The only reason this shows up for
         stateful session is that we moved the SecurityInterceptor to after
         the instance interceptor to allow security exceptions to result in
         invalidation of the session. This may be too literal an interpretation
         of the ejb spec requirement that runtime exceptions should invalidate
         the session.
          */
         if(!callerRunAsIdentityPresent && pushSecurityContext)
         {
            AuthenticationManager am = container.getSecurityManager();
            String securityDomain = SecurityConstants.DEFAULT_APPLICATION_POLICY;
            if(am != null)
               securityDomain = am.getSecurityDomain();
            SecurityActions.createAndSetSecurityContext(mi.getPrincipal(), mi.getCredential(),
                  securityDomain , null);
            //SecurityActions.pushSubjectContext(mi.getPrincipal(), mi.getCredential(), null);
         }

         lock.sync();
         try
         {          
            // Get context
            try
            {
               ctx = cache.get(methodID);
            }
            catch (NoSuchObjectException e)
            {
               if (mi.isLocal())
                  throw new NoSuchObjectLocalException(e.getMessage());
               else
                  throw e;
            }
            catch (EJBException e)
            {
               throw e;
            }
            catch (RemoteException e)
            {
               throw e;
            }
            catch (Exception e)
            {
               InvocationType type = mi.getType();
               boolean isLocal = (type == InvocationType.LOCAL || type == InvocationType.LOCALHOME);
               if (isLocal)
                  throw new EJBException("Unable to get an instance from the pool/cache", e);
               else
                  throw new RemoteException("Unable to get an intance from the pool/cache", e);
            }
           
            // Associate it with the method invocation
            mi.setEnterpriseContext(ctx);
            // Set the JACC EnterpriseBean PolicyContextHandler data
            EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance());

            // BMT beans will lock and replace tx no matter what, CMT do work on transaction
            boolean isBMT = ((SessionMetaData)container.getBeanMetaData()).isBeanManagedTx();
            if (isBMT == false)
            {
              
               // Do we have a running transaction with the context
               if (ctx.getTransaction() != null &&
               // And are we trying to enter with another transaction
               !ctx.getTransaction().equals(mi.getTransaction()))
               {
                  // Calls must be in the same transaction
                  StringBuffer msg = new StringBuffer("Application Error: " +
                     "tried to enter Stateful bean with different tx context");
                  msg.append(", contextTx: " + ctx.getTransaction());
                  msg.append(", methodTx: " + mi.getTransaction());
                  throw new EJBException(msg.toString());
               }

               //If the instance will participate in a new transaction we register a sync for it
               if (ctx.getTransaction() == null && mi.getTransaction() != null)
               {
                  register(ctx, mi.getTransaction(), lock);
               }
            }
           
            if (!ctx.isLocked())
            {
              
               //take it!
               ctx.lock();
            }
            else
            {
               if (!isCallAllowed(mi))
               {
                  // Concurent calls are not allowed
                  throw new EJBException("Application Error: no concurrent " +
                        "calls on stateful beans");
               }
               else
               {
                  ctx.lock();
               }
            }
         }
         finally
         {
            lock.releaseSync();
         }

         // Set the current security information
         /**
          * JBAS-3976: Setting principal on the context has been moved to a separate interceptor
          */

         if (ejbTimeout.equals(mi.getMethod()))
            AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT);
         else
            AllowedOperationsAssociation.pushInMethodFlag(IN_BUSINESS_METHOD);

         boolean validContext = true;
         try
         {
            // Invoke through interceptors
            Object ret = getNext().invoke(mi);
            return ret;
         }
         catch (RemoteException e)
         {
            // Discard instance
            cache.remove(methodID);
            pool.discard(ctx);
            validContext = false;

            throw e;
         }
         catch (RuntimeException e)
         {
            // Discard instance
            cache.remove(methodID);
            pool.discard(ctx);
            validContext = false;

            throw e;
         }
         catch (Error e)
         {
            // Discard instance
            cache.remove(methodID);
            pool.discard(ctx);
            validContext = false;

            throw e;
         }
         finally
         {
            AllowedOperationsAssociation.popInMethodFlag();

            if (validContext)
            {
               // Still a valid instance
               lock.sync();
               try
               {

                  // release it
                  ctx.unlock();
                 
                  // if removed, remove from cache
                  if (ctx.getId() == null)
                  {
                     // Remove from cache
                     cache.remove(methodID);
                     pool.free(ctx);
                  }
               }
               finally
               {
                  lock.releaseSync();
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/*     */   {
/* 124 */     if (getEJBObject.equals(mi.getMethod())) {
/* 125 */       return getNext().invokeHome(mi);
/*     */     }
/*     */
/* 128 */     InstancePool pool = this.container.getInstancePool();
/* 129 */     EnterpriseContext ctx = pool.get();
/*     */
/* 132 */     mi.setEnterpriseContext(ctx);
/*     */
/* 135 */     ctx.lock();
/*     */
/* 142 */     AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_HOME);
/*     */     try
/*     */     {
/* 147 */       localObject1 = getNext().invokeHome(mi);
/*     */     }
/*     */     finally
/*     */     {
/* 151 */       synchronized (ctx)
/*     */       {
/*     */         Object localObject1;
/* 153 */         AllowedOperationsAssociation.popInMethodFlag();
/*     */
/* 156 */         ctx.unlock();
/*     */
/* 159 */         if (ctx.getId() == null)
/*     */         {
/* 161 */           pool.free(ctx);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/* 133 */     EntityContainer ec = (EntityContainer)this.container;
/*     */     InvocationType type;
/* 134 */     if ((mi.getTransaction() == null) ||
/* 138 */       (ctx == null))
/*     */     {
/* 140 */       InstancePool pool = ec.getInstancePool();
/*     */       try
/*     */       {
/* 143 */         ctx = (EntityEnterpriseContext)pool.get();
/*     */       }
/*     */       catch (EJBException e)
/*     */       {
/* 147 */         throw e;
/*     */       }
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/*     */
/*     */   public Object invoke(Invocation mi)
/*     */     throws Exception
/*     */   {
/*  81 */     MessageDrivenContainer mdc = (MessageDrivenContainer)this.container;
/*  82 */     InstancePool pool = mdc.getInstancePool();
/*  83 */     EnterpriseContext ctx = null;
/*     */     try
/*     */     {
/*  86 */       ctx = pool.get();
/*     */     }
/*     */     catch (EJBException e)
/*     */     {
/*  90 */       throw e;
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*  94 */       throw new EJBException("Unable to get an instance from the pool", e);
/*     */     }
/*     */
/*  98 */     ctx.setPrincipal(mi.getPrincipal());
/*     */
/* 101 */     mi.setEnterpriseContext(ctx);
/*     */
/* 103 */     EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance());
/*     */
/* 105 */     if (ejbTimeout.equals(mi.getMethod()))
/* 106 */       AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT);
/*     */     else {
/* 108 */       AllowedOperationsAssociation.pushInMethodFlag(IN_BUSINESS_METHOD);
/*     */     }
/*     */
/*     */     try
/*     */     {
/* 115 */       Object obj = getNext().invoke(mi);
/* 116 */       localObject1 = obj;
/*     */     }
/*     */     catch (RuntimeException e)
/*     */     {
/*     */       Object localObject1;
/* 120 */       mi.setEnterpriseContext(null);
/* 121 */       throw e;
/*     */     }
/*     */     catch (RemoteException e)
/*     */     {
/* 125 */       mi.setEnterpriseContext(null);
/* 126 */       throw e;
/*     */     }
/*     */     catch (Error e)
/*     */     {
/* 130 */       mi.setEnterpriseContext(null);
/* 131 */       throw e;
/*     */     }
/*     */     finally
/*     */     {
/* 135 */       AllowedOperationsAssociation.popInMethodFlag();
/* 136 */       EnterpriseBeanPolicyContextHandler.setEnterpriseBean(null);
/*     */
/* 139 */       if (mi.getEnterpriseContext() != null)
/*     */       {
/* 141 */         pool.free((EnterpriseContext)mi.getEnterpriseContext());
/*     */       }
/*     */       else
/*     */       {
/* 145 */         pool.discard(ctx);
/*     */       }
/*     */     }
/*     */   }
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/*     */     throws Exception
/*     */   {
/* 113 */     EntityContainer container = (EntityContainer)getContainer();
/* 114 */     EntityEnterpriseContext ctx = (EntityEnterpriseContext)container.getInstancePool().get();
/* 115 */     ctx.setTxAssociation(GlobalTxEntityMap.NOT_READY);
/* 116 */     InstancePool pool = container.getInstancePool();
/*     */
/* 119 */     mi.setEnterpriseContext(ctx);
/*     */
/* 122 */     ctx.setTransaction(mi.getTransaction());
/*     */
/* 124 */     ctx.setSecurityContext(mi.getSecurityContext());
/*     */
/* 126 */     ctx.setPrincipal(mi.getPrincipal());
/*     */
/* 128 */     AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_HOME);
/*     */
/* 132 */     Object obj = null;
/* 133 */     Exception exception = null;
/*     */     try
/*     */     {
/* 137 */       obj = getNext().invokeHome(mi);
/*     */
/* 140 */       if (ctx.getId() != null)
/*     */       {
/* 142 */         BeanLock lock = container.getLockManager().getLock(ctx.getCacheKey());
/* 143 */         lock.sync();
/*     */         try
/*     */         {
/* 149 */           cache = container.getInstanceCache();
/* 150 */           cache.remove(ctx.getCacheKey());
/*     */
/* 154 */           cache.insert(ctx);
/*     */         }
/*     */         finally
/*     */         {
/* 158 */           lock.releaseSync();
/* 159 */           container.getLockManager().removeLockRef(ctx.getCacheKey());
/*     */         }
/*     */
/* 163 */         InstanceCache cache = obj;
/*     */         return cache;
/*     */       }
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 168 */       exception = e;
/*     */     }
/*     */     finally
/*     */     {
/* 172 */       AllowedOperationsAssociation.popInMethodFlag();
/*     */     }
/*     */
/* 175 */     ctx.setTransaction(null);
/*     */
/* 177 */     mi.setEnterpriseContext(null);
/*     */
/* 181 */     if (exception == null)
/*     */     {
/* 183 */       container.getInstancePool().free(ctx);
/* 184 */       return obj;
/*     */     }
/*     */
/* 187 */     if ((exception instanceof RuntimeException))
/*     */     {
/* 191 */       pool.discard(ctx);
/*     */     }
/*     */     else
/*     */     {
/* 198 */       pool.free(ctx);
/*     */     }
/*     */
/* 201 */     throw exception;
/*     */   }
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/*     */   }
/*     */
/*     */   public Object invokeHome(Invocation mi)
/*     */     throws Exception
/*     */   {
/*  89 */     InstancePool pool = this.container.getInstancePool();
/*  90 */     StatelessSessionEnterpriseContext ctx = null;
/*     */     try
/*     */     {
/*  94 */       ctx = (StatelessSessionEnterpriseContext)pool.get();
/*  95 */       mi.setEnterpriseContext(ctx);
/*     */
/*  97 */       localObject1 = getNext().invokeHome(mi);
/*     */     }
/*     */     finally
/*     */     {
/*     */       Object localObject1;
/* 101 */       mi.setEnterpriseContext(null);
/*     */
/* 103 */       if (ctx != null)
/* 104 */         pool.free(ctx);
/*     */     }
/*     */   }
View Full Code Here

Examples of org.jboss.ejb.InstancePool

/* 104 */         pool.free(ctx);
/*     */     }
/*     */   }
/*     */
/*     */   public Object invoke(Invocation mi) throws Exception {
/* 112 */     InstancePool pool = this.container.getInstancePool();
/* 113 */     StatelessSessionEnterpriseContext ctx = null;
/*     */     boolean isLocal;
/*     */     try {
/* 116 */       ctx = (StatelessSessionEnterpriseContext)pool.get();
/*     */     }
/*     */     catch (EJBException e)
/*     */     {
/* 120 */       throw e;
/*     */     }
/*     */     catch (RemoteException e)
/*     */     {
/* 124 */       throw e;
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 128 */       InvocationType type = mi.getType();
/* 129 */       isLocal = (type == InvocationType.LOCAL) || (type == InvocationType.LOCALHOME);
/* 130 */       if (isLocal) {
/* 131 */         throw new EJBException("Unable to get an instance from the pool", e);
/*     */       }
/* 133 */       throw new RemoteException("Unable to get an intance from the pool", e);
/*     */     }
/*     */
/* 137 */     ctx.setSecurityContext(mi.getSecurityContext());
/*     */
/* 139 */     ctx.setPrincipal(mi.getPrincipal());
/*     */
/* 141 */     EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance());
/*     */
/* 144 */     mi.setEnterpriseContext(ctx);
/*     */
/* 147 */     Object msgContext = mi.getValue(InvocationKey.SOAP_MESSAGE_CONTEXT);
/*     */
/* 150 */     if (ejbTimeout.equals(mi.getMethod()))
/*     */     {
/* 152 */       AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT);
/*     */     }
/* 156 */     else if (msgContext != null)
/*     */     {
/* 158 */       if ((msgContext instanceof MessageContext)) {
/* 159 */         ctx.setMessageContext((MessageContext)msgContext);
/*     */       }
/* 161 */       AllowedOperationsAssociation.pushInMethodFlag(IN_SERVICE_ENDPOINT_METHOD);
/*     */     }
/*     */     else
/*     */     {
/* 167 */       AllowedOperationsAssociation.pushInMethodFlag(IN_BUSINESS_METHOD);
/*     */     }
/*     */
/*     */     try
/*     */     {
/* 174 */       Object obj = getNext().invoke(mi);
/* 175 */       isLocal = obj;
/*     */     }
/*     */     catch (RuntimeException e)
/*     */     {
/* 180 */       mi.setEnterpriseContext(null);
/* 181 */       throw e;
/*     */     }
/*     */     catch (RemoteException e)
/*     */     {
/* 185 */       mi.setEnterpriseContext(null);
/* 186 */       throw e;
/*     */     }
/*     */     catch (Error e)
/*     */     {
/* 190 */       mi.setEnterpriseContext(null);
/* 191 */       throw e;
/*     */     }
/*     */     finally
/*     */     {
/* 195 */       AllowedOperationsAssociation.popInMethodFlag();
/* 196 */       EnterpriseBeanPolicyContextHandler.setEnterpriseBean(null);
/*     */
/* 199 */       if (mi.getEnterpriseContext() != null)
/*     */       {
/* 201 */         pool.free((EnterpriseContext)mi.getEnterpriseContext());
/*     */       }
/*     */       else
/*     */       {
/* 205 */         pool.discard(ctx);
/*     */       }
/*     */     }
/*     */   }
View Full Code Here

Examples of org.mom4j.xcp.util.InstancePool

       
        Object[] objects = new Object[this.config.getWorkersCount()];
        for(int i = 0; i < objects.length; i++) {
            objects[i] = new XcpDocumentHandler(cfg);
        }
        this.docHandlers = new InstancePool(objects);
    }
View Full Code Here

Examples of org.mom4j.xcp.util.InstancePool

        Integer[] ia = new Integer[num];
        for(int i = 0; i < num; i++) {
            ia[i] = new Integer(i);
        }
       
        InstancePool pool = new InstancePool(ia);
       
        Assert.assertEquals("available size of pool", num, pool.getAvailable());
       
        Integer[] integers = new Integer[num];
        for(int i = 0; i < num; i++) {
            Assert.assertEquals("loop: available size of pool #" + i,
                              num - i,
                              pool.getAvailable());
            integers[i] = (Integer)pool.getObject();
            Assert.assertEquals("loop: integer ", ia[i], integers[i]);
        }
        Assert.assertEquals("available size of pool after loop",
                           0,
                           pool.getAvailable());
       
        long t1 = System.currentTimeMillis();
        new Releaser(pool, integers[0], 3000);
        integers[0] = (Integer)pool.getObject();
        long t2 = System.currentTimeMillis();
       
        Assert.assertTrue("wait()-period", (t2 - t1) > 2500 && (t2 - t1) < 3500);
        Assert.assertEquals("object after release", integers[0], ia[0]);
        Assert.assertEquals("capacity after release", 0, pool.getAvailable());
       
    }
View Full Code Here

Examples of org.mom4j.xcp.util.InstancePool

                //cllient side, so no logging ...
                ex.printStackTrace();
                throw new IllegalStateException(ex.getMessage());
            }
        }
        InstancePool pool = new InstancePool(objects);
       
        this.handlerMap.put(protocol, pool);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.