Package net.ex337.scriptus.model

Examples of net.ex337.scriptus.model.ScriptProcess


    r.visit(new ScriptusFacade(datastore, c, m, conf), p);
  }

  public void test_breakSecurity5() throws IOException {
   
    ScriptProcess p = datastore.newProcess(TEST_USER, "breakSec5.js", false, "", "owner", TransportType.Dummy);
   
        p.save();
       
       
    ScriptAction r = p.call();
   
    assertEquals("Failed correctly", ErrorTermination.class, r.getClass());
           
    System.out.println(((ErrorTermination)r).getError());
   
View Full Code Here


    protected void tearDown() throws Exception {
    }

    public void test_ask() throws IOException {

        ScriptProcess p = datastore.newProcess(TEST_USER, "ask.js", false, "", "owner", TransportType.Twitter);

        ScriptAction r = p.call();

        assertTrue("Asked correctly", r instanceof Ask);
        assertTrue("Asked correctly foo", ((Ask) r).getWho().equals("ianso"));

        p.save();

        final ThreadLocal<String> tweetId = new ThreadLocal<String>();

        ScriptusFacade f = new ScriptusFacade(datastore, c, m, config) {
View Full Code Here

    }

    public void test_listen() throws IOException {

        ScriptProcess p = datastore.newProcess(TEST_USER, "listen.js", false, "", "owner", TransportType.Twitter);

        ScriptAction r = p.call();

        assertTrue("listened correctly", r instanceof Listen);
        assertTrue("listened correctly to no-one", ((Listen) r).getWho() == null);

        p.save();

//        final ThreadLocal<String> tweetId = new ThreadLocal<String>();

        ScriptusFacade f = new ScriptusFacade(datastore, c, m, config) {
View Full Code Here

  }

 
  public void test_evalGet() throws IOException {
   
    ScriptProcess p = datastore.newProcess(TEST_USER, "evalget.js", false, "", "owner", TransportType.Dummy);
   
    ScriptAction r = p.call();
   
    assertTrue("slept correctly", r instanceof Get);

    p.save();

    Get g = (Get) r;
   
    g.visit(new ScriptusFacade(datastore, c, m, conf), p);
   
    p = datastore.getProcess(p.getPid());
   
    assertTrue("got content", p.getState() instanceof String);
   
    r = p.call();
   
    assertTrue("said correctly", r instanceof Say);
   
    System.out.println(((Say)r).getMsg());
   
View Full Code Here

   
   
    LOG.debug("Forking "+parent.getPid().toString().substring(30)+", child="+childPid.toString().substring(30));
   
    ScriptProcess child = parent.clone();
    //fork() response
    child.setState(0);
    child.setRoot(false);
   
    //important :-/
    child.setPid(childPid);
   
    child.save();
   
    scriptus.execute(child.getPid());
   
    scriptus.execute(parent.getPid());
   
  }
View Full Code Here

      scriptus.runWithLock(childPid, new Runnable() {

        @Override
        public void run() {
         
          ScriptProcess child = scriptus.getProcess(childPid); //overwrites state with child
         
          //already terminated
          if(child.getState() instanceof Termination) {

            //FIXME we should delete child & remove from list of children
            scriptus.updateProcessState(parentPid, ((Termination)child.getState()).getResult());

            scriptus.execute(parentPid);

            return;
           
          }
         
          LOG.debug("registering waiter for " + childPid.toString().substring(30) + ", waiterpid="
              + parentPid.toString().substring(30));
         
          child.setWaiterPid(parentPid);
          child.save();
         
        }
      });

View Full Code Here

            if (d == null) {
                throw new ProcessNotFoundException(pid.toString());
            }

            ScriptProcess result = createScriptProcess();

            result.setPid(UUID.fromString(d.pid));
            if (d.waitingPid != null) {
                result.setWaiterPid(UUID.fromString(d.waitingPid));
            }
            result.setSource(new String(d.source, ScriptusConfig.CHARSET));
            result.setSourceName(d.sourceId);
            result.setUserId(d.userId);
            result.setArgs(d.args);
            result.setTransport(TransportType.valueOf(d.transport));

            {
                ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(d.script_state));

                result.setCompiled((Function) in.readObject());
                result.setGlobalScope((ScriptableObject) in.readObject());
                result.setContinuation(in.readObject());

            }

            result.setState(SerializableUtils.deserialiseObject(d.state));
            result.setOwner(d.owner);
            result.setRoot(d.isRoot);
            result.setVersion(d.version);
            result.setAlive(d.isAlive);

            return result;

        } catch (ScriptusRuntimeException e) {
            throw e;
View Full Code Here

       */
      scriptus.runWithLock(pid, new Runnable() {
        @Override
        public void run() {
          try {
            ScriptProcess child = scriptus.getProcess(pid);

            if(child.getState() instanceof HasTimeout) {
              //delete wake if it exists, should fail silently
              scriptus.deleteScheduledTask(pid, ((HasTimeout)child.getState()).getNonce());
            }
           
            scriptus.markAsKilledIfRunning(pid);
           
            child.delete();
            scriptus.removeChild(parent, pid);
            process.save();

          } catch(ProcessNotFoundException sre) {
            //do onthing & continue;
View Full Code Here

  /* (non-Javadoc)
   * @see net.ex337.scriptus.ProcessScheduler#newProcess(java.lang.String, java.lang.String, java.lang.String, java.lang.String, TransportType)
   */
  @Override
  public void executeNewProcess(String userId, String sourceName, boolean sample, String args, String owner, TransportType transport) {
    ScriptProcess p = datastore.newProcess(userId, sourceName, sample, args, owner, transport);
    p.save();
    execute(p.getPid());
  }
View Full Code Here

  public void markAsKilledIfRunning(UUID pid) {
    /**
     * FIXME still possibility of process finishing call() between the get and the kill() call...
     */
    ScriptProcess toKill = runningProcesses.get(pid);
    if(toKill == null) return;
    toKill.kill();
  }
View Full Code Here

TOP

Related Classes of net.ex337.scriptus.model.ScriptProcess

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.