Package nexj.core.runtime

Examples of nexj.core.runtime.InvocationContext


    * @param sType The integration message type name.
    */
   protected void run(ContextRunnable strategy, Channel channel, String sType)
   {
      Context contextSaved = ThreadContextHolder.getContext();
      InvocationContext context = null;
      int nCookie = -1;

      try
      {
         if (!strategy.isEnabled())
         {
            return;
         }

         context = (InvocationContext)m_contextComponent.getInstance(null);

         String sAddress = strategy.getClientAddress();

         context.setClientAddress(sAddress);
        
         if (sAddress != null)
         {
            nCookie = Logger.pushContext(sAddress);
         }

         String sUser = strategy.getUser();

         context.initialize((sUser != null) ? new SimplePrincipal(sUser) : null);

         int nUserCookie = Logger.pushContext(context.getPrincipal().getName());

         if (nCookie == -1)
         {
            nCookie = nUserCookie;
         }

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Received a " + sType + " message from " +
               context.getPrincipal().getName() + ((sAddress == null) ? "" : " @ " + sAddress) +
               " on channel \"" + channel.getName() + "\"");
         }

         strategy.run(context);
         context.complete(true);

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Completed processing the " + sType + " message");
         }
      }
      catch (Throwable e)
      {
         int nLevel = (ObjUtil.isError(e)) ? Logger.ERROR : Logger.DEBUG;

         if (s_logger.isLevelEnabled(nLevel))
         {
            s_logger.log(nLevel, "Error processing the " + sType + " message", e);
         }

         try
         {
            if (context != null)
            {
               context.complete(false);
            }
         }
         catch (Throwable t)
         {
            s_logger.error("Unable to complete the processing", t);
View Full Code Here


            if (!(classObj instanceof Metaclass))
            {
               throw new TypeMismatchException(getSymbol());
            }
           
            InvocationContext context = (InvocationContext)machine.getContext();
            Metaclass metaclass = (Metaclass)classObj;
            Instance instance;

            if (oidArray != null)
            {
               OID oid;
              
               if (oidArray instanceof Object[])
               {
                  oid = new OID((Object[])oidArray);
               }
               else if (oidArray instanceof OID)
               {
                  oid = (OID)oidArray;
               }
               else
               {
                  throw new TypeMismatchException(getSymbol());
               }

               instance = context.findInstance(metaclass, oid);

               if (instance == null)
               {
                  instance = new Instance(metaclass, context);
                  instance.cache(oid);
View Full Code Here

      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            if (machine.isStackEmpty(nArgCount))
            {
               InvocationContext context = (InvocationContext)machine.getContext();

               if (context.isAudited())
               {
                  verifyArgCount(nArgCount, 2);

                  PCodeFunction fun = (PCodeFunction)machine.getArg(0, nArgCount);
                  Object[] frame = fun.frame;
View Full Code Here

      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            verifyArgCount(nArgCount, 0, 1);

            InvocationContext context = (InvocationContext)machine.getContext();
            int nTimeout = -1;

            if (nArgCount > 0)
            {
               Number number = (Number)machine.getArg(0, nArgCount);

               if (number != null)
               {
                  nTimeout = number.intValue();
               }
            }

            machine.returnValue(context.beginTransaction(true, nTimeout), nArgCount);

            return false;
         }

         public Symbol getSymbol()
View Full Code Here

            if (!(name instanceof String))
            {
               throw new TypeMismatchException(getSymbol());
            }

            InvocationContext context = (InvocationContext)machine.getContext();
            PrimitivePrivilege privilege = context.getMetadata().getPrimitivePrivilege((String)name);

            machine.returnValue(Boolean.valueOf(context.getPrivilegeSet().contains(privilege)), nArgCount);

            return false;
         }

         public Symbol getSymbol()
View Full Code Here

               break;
            }
         }
      }

      InvocationContext context = getInvocationContext();

      if (!bDirty)
      {
         context.getGlobalCache().update(null, cacheMap, context.getUnitOfWork().getTime());
      }

      for (Lookup.Iterator itr = cacheMap.iterator(); itr.hasNext();)
      {
         itr.next();
         context.getUnitOfWork().cacheTemporary(itr.getKey(), itr.getValue(), UnitOfWork.CACHE_UNPARTITIONED);
      }
   }
View Full Code Here

    */
   protected InstanceList readCached()
   {
      assert isCached();

      InvocationContext context = getInvocationContext();
      Lookup identityMap = new HashTab(4);
      boolean bCached = true;

      for (;;)
      {
View Full Code Here

      {
         public boolean invoke(int nArgCount, Machine machine)
         {
            assert nArgCount == 2;

            InvocationContext context = (InvocationContext)machine.getContext();
            TransferObject tobj = (TransferObject)machine.getArg(0, nArgCount);
            State state = (State)machine.getArg(1, nArgCount);
            String sChannelName = (m_channel != null) ? (String)m_channel.invoke(machine, state, new Object[]{tobj}) : null;

            if (sChannelName == null)
            {
               sChannelName = (String)tobj.findValue(Sender.CHANNEL);
            }

            if (sChannelName == null)
            {
               throw new IllegalArgumentException("Unspecified channel for Send");
            }

            Channel channel = context.getMetadata().getChannel(sChannelName);

            context.getUnitOfWork().addMessage(channel, format(tobj, (Sender)channel.getSender().getInstance(context), context));
            machine.returnValue(tobj, nArgCount);

            return false;
         }
      };
View Full Code Here

    * verify that the operations are performed successfully.
    */
   public void testCreateReadUpdateDelete() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data.".getBytes("utf-8")));
        
         commit(context);
       
         OID oidA = a.getOID();
         String sOidName = (String)oidA.getValue(0);
        
         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidName + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data.".getBytes("utf-8")), a.getValue("data"));
  
         // Update
         a.setValue("data", new Binary("Update data.".getBytes("utf-8")));
        
         commit(context);
        
         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidName + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Update data.".getBytes("utf-8")), a.getValue("data"));
        
         // Delete
         a.invoke("delete");
        
         commit(context);
        
         // Read (NOT FOUND)
         assertNull(context.beginTransaction());
           
         Query query = Query.createRead(testFPA, null, parse("(= (@ id) \"" + sOidName + "\")"), null, 10, 0, false, Query.SEC_NONE, context);
         InstanceList resultList = query.read();
           
         assertEquals(0, resultList.getCount());
        
         commit(context);

         // Create it (test that the read operation doesn't add the not-found instance to the invocation context)
         assertNull(context.beginTransaction());

         a = (Instance)testFPA.invoke("new");
         a.setOID(oidA);
         a.setValue("data", new Binary("Creation data #2.".getBytes("utf-8")));

         commit(context);
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
      }
   }
View Full Code Here

    * Tests that the adapter can create multiple files in one transaction.
    */
   public void testCreateMultiple() throws Exception
   {
      Metadata metadata = loadMetadata("filestorage");
      InvocationContext context = new InvocationContext(metadata);
     
      try
      {
         ThreadContextHolder.setContext(context);
     
         /* ***** Configure the data source connection with temporary directories ***** */
         File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
         File tempDir = new File(mainDir, "temp");
         File dataDir = new File(mainDir, "data");
         File jrnlDir = new File(mainDir, "journal");
        
         assertTrue(tempDir.mkdir());
         assertTrue(dataDir.mkdir());
         assertTrue(jrnlDir.mkdir());
        
        
         DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
        
         assertEquals(1, ds.getFragmentCount());
        
         FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
        
         defaultFrag.debugSettings(dataDir.getAbsolutePath(),
            tempDir.getAbsolutePath(),
            jrnlDir.getAbsolutePath());
        
        
         // Create it
         assertNull(context.beginTransaction());
        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Instance a = (Instance)testFPA.invoke("new");
        
         a.setValue("data", new Binary("Creation data for 'a'.".getBytes("utf-8")));
        
         Instance b = (Instance)testFPA.invoke("new");
        
         b.setValue("data", new Binary("Creation data for 'b'.".getBytes("utf-8")));
        
         commit(context);
       
         OID oidA = a.getOID();
         String sOidNameA = (String)oidA.getValue(0);
         OID oidB = b.getOID();
         String sOidNameB = (String)oidB.getValue(0);

         // Read
         assertNull(context.beginTransaction());
         a.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidNameA + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data for 'a'.".getBytes("utf-8")), a.getValue("data"));
  
         b.invoke("read", new Object[]{
            parse("(data)"),
            parse("(= (@ id) \"" + sOidNameB + "\")"), null, null, null, null
         });
         assertEquals(new Binary("Creation data for 'b'.".getBytes("utf-8")), b.getValue("data"));

         commit(context);
      }
      finally
      {
         context.complete(false);
         ThreadContextHolder.setContext(null);
      }
   }
View Full Code Here

TOP

Related Classes of nexj.core.runtime.InvocationContext

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.