Package nexj.core.runtime

Examples of nexj.core.runtime.InvocationContext


      m_soapRequest = new SOAPRequest(m_request);
      m_soapResponse = new SOAPResponse(m_response);
      m_soapFault = new SOAPFault(m_exception);

      m_marshaller = new SOAPMarshaller(new InvocationContext(Repository.getMetadata()));
      m_unmarshaller = new SOAPUnmarshaller(new InvocationContext(Repository.getMetadata()));
   }
View Full Code Here


         public void run(InvocationContext context) throws Throwable
         {
            if (message instanceof InvocationContextHolder)
            {
               InvocationContext ctx = ((InvocationContextHolder)message).getInvocationContext();

               if (ctx != null && ctx.getTester() != null)
               {
                  context.setTester(ctx.getTester());
               }
            }

            if (m_channel.isTrusted())
            {
View Full Code Here

      m_bWritable = ((nFlags & WRITABLE) != 0);
      m_helper = new XMLMetadataHelper(rootURL, baseURL, m_properties, null, handler);
      m_metadata = createXMLMetadata(sURI, rootURL, baseURL, (m_bValidatedOnly) ? m_helper : null);
      m_metadata.setConfigurationURL(configURL);
      m_machine = new Machine(m_metadata.getGlobalEnvironment(),
         new InvocationContext(m_metadata, m_metadata.getGlobalEnvironment()));
      m_enumerationValueMap = new HashTab(16);
      m_inheritanceCheckList = new ArrayList();
      m_inheritanceFixupList = new ArrayList();
      m_inheritance1stPassFixupList = new ArrayList();
      m_inheritance2ndPassFixupList = new ArrayList(1);
View Full Code Here

            instance.assign(attribute, value, true);

            if (pre != Undefined.VALUE)
            {
               InvocationContext context = instance.getInvocationContext();
               byte nGenerationSaved = context.getGeneration();

               try
               {
                  context.setGeneration(InvocationContext.GEN_PRE);
                  instance.assign(attribute, pre, true);
               }
               finally
               {
                  context.setGeneration(nGenerationSaved);
               }
            }
         }
      }
      finally
View Full Code Here

         if (s_logger.isDebugEnabled())
         {
            s_logger.debug("Polling timer \"" +  m_thisComponent.getName() + "\"");
         }

         InvocationContext context = (InvocationContext)m_contextComponent.getInstance(null);
         int nCookie = -1;

         try
         {
            context.initialize(null);
            context.setSecure(false);
            context.setPartitioned(false);
            nCookie = Logger.pushContext(context.getPrincipal().getName());

            Metadata metadata = context.getMetadata();
            Metaclass timerClass = metadata.getMetaclass("SysTimer");
            Pair attributes =
               new Pair(Symbol.define("next"),
               new Pair(Symbol.define("start"),
               new Pair(Symbol.define("period"),
               new Pair(Symbol.define("principal"),
               new Pair(Symbol.define("data"))))));
            Pair orderBy = new Pair(new Pair(Symbol.define("next"), Boolean.TRUE));
            List sendList = null;

         loop:
            for (;;)
            {
               context.beginTransaction();
               context.getUnitOfWork().setRaw(true);

               long lCurrentTime = System.currentTimeMillis();
               InstanceList list = Query.createRead(timerClass, attributes,
                  (m_bDistributed) ? Pair.attribute("next").le(new Timestamp(lCurrentTime + m_lInterval)) : null,
                  orderBy, m_nBatchCount, 0, true, Query.SEC_NONE, context).read();

               for (int i = 0; i < list.size(); ++i)
               {
                  Instance timer = list.getInstance(i);
                  long lNextTimeout = ((Timestamp)timer.getValue("next")).getTime();

                  if (lNextTimeout <= lCurrentTime)
                  {
                     String sId = timer.getOID().getValue(0).toString();
                     TransferObject properties = new TransferObject(3);

                     properties.setValue("timer", sId);
                     properties.setValue(JMSSender.PROTECTED, Boolean.FALSE);

                     Object user = timer.getValue("principal");

                     if (user == null)
                     {
                        user = m_sDefaultUser;
                     }

                     if (user != null)
                     {
                        properties.setValue(JMSSender.USER, user);
                     }

                     if (s_logger.isDebugEnabled())
                     {
                        s_logger.debug("Timeout in timer \"" +  m_thisComponent.getName() +
                           "\", id=" + sId + "; forwarding to the message queue");
                     }

                     TransferObject tobj = new TransferObject(2);

                     tobj.setValue(JMSSender.BODY, ((Binary)timer.getValue("data")).toObject());
                     tobj.setValue(JMSSender.PROPERTIES, properties);

                     if (sendList == null)
                     {
                        sendList = new ArrayList(m_nBatchCount);
                     }

                     sendList.add(tobj);

                     long lPeriod = ((Number)timer.getValue("period")).longValue();

                     if (lPeriod <= 0)
                     {
                        timer.invoke("delete");
                     }
                     else
                     {
                        Timestamp tmStart = (Timestamp)timer.getValue("start");

                        lNextTimeout = tmStart.getTime() + lPeriod * ((lCurrentTime - tmStart.getTime()) / lPeriod + 1);
                        timer.setValue("next", new Timestamp(lNextTimeout));
                        reset(lNextTimeout, false);
                     }
                  }
                  else
                  {
                     reset(lNextTimeout, false);

                     break loop;
                  }
               }

               if (list.size() < m_nBatchCount)
               {
                  break;
               }

               if (sendList != null)
               {
                  m_queueClient.send(sendList);
                  sendList = null;
               }

               context.complete(true);
               context.initUnitOfWork();
            }

            if (sendList != null)
            {
               m_queueClient.send(sendList);
               sendList = null;
            }

            context.complete(true);

            // Defer the timeout in the other nodes

            if (m_bDistributed)
            {
               synchronized (this)
               {
                  long lCurrentTime = System.currentTimeMillis();

                  if (m_lTimeout - lCurrentTime >= (m_lInterval >> 1) ||
                     lCurrentTime - m_lDeferralTime >= (m_lInterval >> 1))
                  {
                     m_lDeferralTime = lCurrentTime;

                     TransferObject properties = new TransferObject(1);

                     properties.setValue(JMSSender.NODE, J2EEUtil.NODE_ID);

                     TransferObject tobj = new TransferObject(2);

                     tobj.setValue(JMSSender.BODY, new DeferTimeoutCommand(m_thisComponent.getName()));
                     tobj.setValue(JMSSender.PROPERTIES, properties);

                     m_topicClient.send(tobj);
                  }
               }
            }
         }
         catch (Throwable t)
         {
            context.complete(false);

            throw t;
         }
         finally
         {
View Full Code Here

         s_logger.debug("The mail client is disabled, skipping poll request.");

         return;
      }

      InvocationContext context = (InvocationContext)ThreadContextHolder.getContext();
      Instance oldUser = context.getUser();
      String sOldAddress = context.getClientAddress();
      int nCookie = -1;

      try
      {
         String sAddress = m_channel.getInHost();
         String sUser = m_channel.getDefaultUser();

         context.setClientAddress(sAddress);

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

         context.login((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 Mail message from " +
               context.getPrincipal().getName() + ((sAddress == null) ? "" : " @ " + sAddress) +
               " on channel \"" + m_channel.getName() + "\"");
         }

         poll(context);

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

         s_logger.log(nLevel, "Error processing the Mail message", e);

         throw new ServerException("err.rpc.mail", e);
      }
      finally
      {
         if (nCookie != -1)
         {
            Logger.resetContext(nCookie);
         }

         context.setClientAddress(sOldAddress);
         context.login(oldUser);
      }
   }
View Full Code Here

            if (bInit)
            {
               m_globalEnv = new GlobalEnvironment(metadata.getGlobalEnvironment());
            }

            InvocationContext context = (InvocationContext)metadata.getComponent("System.InvocationContext").getInstance(null);

            context.setAudited(false);
            context.initialize(null, m_globalEnv);
            context.setLocale(m_locale);

            Machine machine = context.getMachine();

            if (bInit)
            {
               InputStream istream = null;
               Reader reader = null;

               try
               {
                  istream = URLUtil.openResource(UnitTest.class, INITIAL_SCRIPT);
                  reader = new BufferedReader(new InputStreamReader(istream, XMLUtil.ENCODING));
                  Intrinsic.load(reader, INITIAL_SCRIPT_URL, machine);
               }
               catch (IOException e)
               {
                  throw new MetadataException("err.meta.resourceOpen", new Object[]{INITIAL_SCRIPT}, e);
               }
               finally
               {
                  IOUtil.close(reader);
                  IOUtil.close(istream);
               }
            }

            UnitTest utest = (UnitTest)m_unitTestList.get(nUnitTest);

            for (Iterator argItr = new ArgumentIterator(context, utest); argItr.hasNext(); )
            {
               Object[] variableArray = (Object[])argItr.next();
               String sTestArguments = formatLoopVariables(variableArray, utest.getLoopCount());
               DataLoader dataLoader = new DataLoader(context);
               URL dumpURL = getDumpURL(utest);
               boolean bResetDB = dumpURL != null;

               m_unitTestLogger.begin(utest, sTestArguments);

               if (bResetDB && !bReady)
               {
                  if (m_container != null)
                  {
                     m_container.suspend();
                  }

                  bReady = true;

                  if (nUnitTest == 0)
                  {
                     try
                     {
                        dataLoader.recreateSchema((Set)null);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                  }
                  else
                  {
                     bFirstRun = false;
                  }
               }

               byte nMode = utest.getMode();
               int nTestCase = 0;

               if (utest.hasInitializer())
               {
                  ++nTestCase;
               }

               if (utest.hasFinalizer())
               {
                  ++nTestCase;
               }

               Object[] functionObjArray = null;

               if (utest.getFunction() != null)
               {
                  functionObjArray = (Object[])context.getMachine().invoke(utest.getFunction(), variableArray);
               }

               boolean bFirstTestCase = true;

               for (Iterator itr = utest.getUnitTestCaseIterator(); itr.hasNext();
                  bFirstRun = false, bFirstTestCase = false, bResetDB = dumpURL != null && nMode != UnitTest.MODE_DIRTY)
               {
                  UnitTestCase testCase = (UnitTestCase)itr.next();

                  if (!isEnabled(utest, testCase))
                  {
                     nTestCase++;
                     continue;
                  }

                  if (bResetDB)
                  {
                     if (!bFirstTestCase && m_container != null)
                     {
                        m_container.suspend();
                     }

                     if (!bFirstRun)
                     {
                        try
                        {
                           dataLoader.deleteData((Set)null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(utest, e);

                           return;
                        }
                     }

                     InputStream in = null;

                     try
                     {
                        in = new BufferedInputStream(URLUtil.openStream(dumpURL));
                        dataLoader.importData(in, true);
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(utest, e);

                        return;
                     }
                     finally
                     {
                        IOUtil.close(in);
                        in = null;
                     }
                  }

                  context.complete(true);
                  context.getMachine().cleanup();
                  context.initUnitOfWork();

                  final InvocationContext testContext = (InvocationContext)metadata
                     .getComponent("System.InvocationContext").getInstance(null);

                  try
                  {
                     testContext.setAudited(false);
                     testContext.getGlobalCache().clear();
                     testContext.initialize((m_sSystemUser == null) ? null : new SimplePrincipal(m_sSystemUser),
                        new GlobalEnvironment(m_globalEnv));

                     if (m_container != null && m_sSystemUser != null)
                     {
                        Event grantDebugEvent = testContext.getUserClass().findEvent(GRANT_DEBUG, 0);

                        if (grantDebugEvent != null)
                        {
                           boolean bSecure = testContext.isSecure();

                           try
                           {
                              testContext.setSecure(false);
                              grantDebugEvent.invoke(testContext.getUser(), (Pair)null, testContext.getMachine());
                           }
                           finally
                           {
                              testContext.setSecure(bSecure);
                           }
                        }
                     }

                     if (bResetDB && m_container != null)
                     {
                        m_container.resume();

                        // Suspend the thread if in script debugging mode
                        if (m_bDebug)
                        {
                           PCodeFunction nextFunction = (PCodeFunction)((utest.hasInitializer()) ? functionObjArray[0]
                              : functionObjArray[nTestCase]);

                           s_logger.debug("Waiting for script debugger to connect");

                           try
                           {
                              Class clazz = Class.forName("nexj.core.scripting.debugger.server.GenericDebugSessionManager");
                             
                              Object debugSessionManager = clazz.getMethod("getInstance", null).invoke(null, null);
                             
                              clazz.getMethod("suspendOnStartup", new Class[]{PCodeLocation.class})
                                 .invoke(debugSessionManager, new Object[]{new PCodeLocation(nextFunction, 0)});
                           }
                           catch(Throwable t)
                           {
                              ObjUtil.rethrow(t);
                           }
                        }

                        ThreadContextHolder.setContext(testContext);
                     }

                     if (utest.hasInitializer())
                     {
                        try
                        {
                           testContext.getMachine().invoke((Function)functionObjArray[0], (Object[])null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(testCase, e);
                           ++nErrorCount;

                           continue;
                        }
                     }

                     m_unitTestLogger.begin(testCase);

                     try
                     {
                        nTestCaseCount++;
                        testContext.getMachine().invoke((Function)functionObjArray[nTestCase++], (Object[])null);
                        m_unitTestLogger.end(testCase);
                     }
                     catch (UnitTestAssertionException e)
                     {
                        m_unitTestLogger.fail(testCase, e);
                        ++nFailureCount;
                     }
                     catch (Throwable e)
                     {
                        m_unitTestLogger.err(testCase, e);
                        ++nErrorCount;
                     }

                     if (utest.hasFinalizer())
                     {
                        try
                        {
                           testContext.getMachine().invoke(
                              (Function)functionObjArray[(!utest.hasInitializer()) ? 0 : 1],
                              (Object[])null);
                        }
                        catch (Throwable e)
                        {
                           m_unitTestLogger.err(testCase, e);
                           ++nErrorCount;
                        }
                     }
                  }
                  finally
                  {
                     testContext.complete(false);
                     testContext.getGlobalCache().clear();
                     ThreadContextHolder.setContext(context); //context of DataLoader
                  }

                  bReady = false;
               }
View Full Code Here

            Thread.sleep(m_lTimeout);
            m_bTimedOut = true;
           
            for (Lookup.Iterator itr = m_contextMap.iterator(); itr.hasNext(); )
            {
               InvocationContext context = (InvocationContext)itr.next();
              
               try
               {
                  context.cancel();
                 
                  if (((Boolean)itr.getValue()).booleanValue())
                  {
                     context.complete(false);
                  }
               }
               catch (Throwable t)
               {  // do nothing
               }
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 SendReceive");
            }

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

            context.getUnitOfWork().checkTransaction();

            if (channel.isSynchronous())
            {
               Component sender = channel.getSender();
View Full Code Here

            try
            {
               assert nArgCount == Pair.length(getArguments());

               InvocationContext context = (InvocationContext)machine.getContext();
               TransferObject tobj = (TransferObject)machine.getArg(0, nArgCount);
               Message message = context.getMetadata().getMessage(tobj.getClassName());
               Format format = message.getFormat();

               if (format == null || !format.getName().equals("Object"))
               {
                  throw new IntegrationException("err.integration.persistFormat",
                     new Object[]{message.getName(), (format == null) ? "" : message.getFormat().getName()});
               }

               context.getUnitOfWork().checkTransaction();

               ObjectOutput out = new ObjectOutput();
               MessageFormatter messageFormatter = (MessageFormatter)format.getFormatter().getInstance(context);

               cleanupToken = configureFormatter(messageFormatter, nArgCount, machine);
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.