Examples of ScriptusRuntimeException


Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

//      System.out.println(ss.exec(cx, globalScope));
     
//      System.out.println(cx.evaluateString(globalScope, "scriptus.foo();", "<test>", 1, null));
     
    } catch (Exception e) {
      throw new ScriptusRuntimeException(e);
    } finally {
      Context.exit();
    }
   
  }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

    @Override
    @Transactional(readOnly = true)
    public ScriptProcess getProcess(UUID pid) {

        if (pid == null) {
            throw new ScriptusRuntimeException("Cannot load null pid");
        }

        LOG.debug("loading " + pid.toString().substring(30));

        Context cx = Context.enter();
        cx.setClassShutter(new ScriptusClassShutter());
        cx.setOptimizationLevel(-1); // must use interpreter mode

        try {

            ProcessDAO d;

            try {
                d = em.find(ProcessDAO.class, pid.toString());
            } catch (PersistenceException pe) {
                System.out.println("count="
                        + em.createQuery("select count(*) from ProcessDAO d where d.pid = '" + pid.toString() + "'")
                                .getSingleResult());
                throw pe;
            }

            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;
        } catch (IOException e) {
            throw new ScriptusRuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new ScriptusRuntimeException(e);
        } finally {
            Context.exit();
        }

    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

                d.created = d.lastmod = System.currentTimeMillis();
            } else {

                d = em.find(ProcessDAO.class, p.getPid().toString());
                if (d == null) {
                    throw new ScriptusRuntimeException("Process not found for pid " + p.getPid());
                }

                d.lastmod = System.currentTimeMillis();
            }

            d.args = p.getArgs();

            {
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream(bout);
                out.writeObject(p.getCompiled());
                out.writeObject(p.getGlobalScope());
                out.writeObject(p.getContinuation());
                out.close();
                d.script_state = bout.toByteArray();
            }

            d.state = SerializableUtils.serialiseObject(p.getState());
            d.isRoot = p.isRoot();
            d.owner = p.getOwner();
            d.source = p.getSource().getBytes(ScriptusConfig.CHARSET);
            d.sourceId = p.getSourceName();
            d.userId = p.getUserId();
            d.isAlive = p.isAlive();
            d.transport = p.getTransport().toString();
            d.version = p.getVersion() + 1;
            p.setVersion(d.version);
            if (p.getWaiterPid() != null) {
                d.waitingPid = p.getWaiterPid().toString();
            }

            em.persist(d);

            // datastore.writeProcess(getPid(), bout.toByteArray());

        } catch (ScriptusRuntimeException e) {
            throw e;
        } catch (IOException e) {
            throw new ScriptusRuntimeException(e);
        } finally {
            Context.exit();
        }

    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

            d.when = task.getWhen();

            em.persist(d);

        } else {
            throw new ScriptusRuntimeException("unknown scheduled action " + task);
        }

    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

        if (dao.action.equalsIgnoreCase("wake")) {
            Wake w = new Wake(UUID.fromString(dao.pid), dao.nonce, dao.when);
            r = w;
        } else {
            throw new ScriptusRuntimeException("unkown type of action " + dao.action);
        }

        return r;
    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

                Query q = em
                        .createQuery("update ProcessDAO d set d.state = :state, d.state_label = :label where d.pid= :pid");
                try {
                    q.setParameter("state", SerializableUtils.serialiseObject(o));
                } catch (IOException e) {
                    throw new ScriptusRuntimeException(e);
                }
                q.setParameter("pid", pid.toString());
                q.setParameter("label", label);

                int rows = q.executeUpdate();

                if (rows != 1) {
                    throw new ScriptusRuntimeException("no rows updated for pid " + pid);
                }
            }

        });
    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

        q.setParameter("pid", pid.toString());

        int rows = q.executeUpdate();

        if (rows != 1) {
            throw new ScriptusRuntimeException("no rows updated for pid " + pid);
        }

    }
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

        d.transport = transportType.toString();

        TransportTokenDAO dd = em.find(TransportTokenDAO.class, d);

        if(dd == null) {
            throw new ScriptusRuntimeException("no token found for user"+userId+", transport "+transportType);
        }
       
        TransportAccessToken t = createTransportAccessToken();

        t.load(dd);
View Full Code Here

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

    LOG.debug("waiting for "+childPid.toString().substring(30));
   
    final UUID parentPid = process.getPid();
   
        if( ! scriptus.getChildren(parentPid).contains(childPid)) {
      throw new ScriptusRuntimeException("not a child: "+childPid);
    }
       
        scriptus.updateProcessState(parentPid, this);

    try {
     
      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();
         
        }
      });


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

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException

      String content = IOUtils.toString(c.getInputStream(), c.getContentEncoding());
      scriptus.updateProcessState(process.getPid(), content);
      scriptus.execute(process.getPid());
      //TODO make a ConvertsToScriptable object that will add headers property etc.
    } catch(IOException e) {
      throw new ScriptusRuntimeException(e);
    }

   
  }
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.