Package net.ex337.scriptus.exceptions

Examples of net.ex337.scriptus.exceptions.ScriptusRuntimeException


  }

  @Override
  protected void setUp() throws Exception {
     
      ScriptusConfig c = new ScriptusConfig();
      c.init();
     
//      System.setProperty("DatastoreType", c.getDatastoreType().toString());

      appContext = new ClassPathXmlApplicationContext(new String[]{getConfigFile()}, false);
      appContext.getEnvironment().getPropertySources().addFirst(c.new ScriptusConfigPropertySource("ScriptusConfig", c));
View Full Code Here


  }

  public void test_scheduleTask() throws IOException {
   
    ScriptusDatastore datastore = (ScriptusDatastore) appContext.getBean("datastore");
   
    Calendar then = Calendar.getInstance();
    then.add(Calendar.HOUR, 3);
   
    Wake w = new Wake(UUID.randomUUID(), 1234, then.getTimeInMillis());
   
    datastore.saveScheduledTask(w);
   
    List<ScheduledScriptAction> actions = datastore.getScheduledTasks(Calendar.getInstance());
   
    assertFalse("doesnt contain task in future", actions.contains(w));
   
    actions = datastore.getScheduledTasks(then);
   
    assertTrue("contains task in future",  actions.contains(w));
   
    boolean found = false;
   
    Wake neww = null;
   
    for(ScheduledScriptAction t : actions){
      if(t.equals(w)) {
        neww = (Wake) t;
        found = true;
        break;
      }
    }
   
    assertTrue("retrieved task", found);
   
    then.add(Calendar.HOUR, 1);
   
    actions = datastore.getScheduledTasks(then);
   
    assertTrue("list not empty",  ! actions.isEmpty());
   
    found = false;
   
    for(ScheduledScriptAction t : actions){
      if(t.equals(w)) {
        found = true;
        break;
      }
    }
   
    datastore.deleteScheduledTask(neww.getPid(), neww.getNonce());

    actions = datastore.getScheduledTasks(then);
   
    found = false;
   
    for(ScheduledScriptAction t : actions){
      if(t.equals(w)) {
View Full Code Here

public class Testcase_BootSpring extends BaseTestCase {

 
  public void test_doNothing() throws IOException {
    ScriptusDatastore datastore = (ScriptusDatastore) appContext.getBean("datastore");
  }
View Full Code Here

       
        String uid = UUID.randomUUID().toString();
        String msg = UUID.randomUUID().toString();
        String parent = UUID.randomUUID().toString();
       
        PersonalTransportMessageDAO m = new PersonalTransportMessageDAO();
        m.userId = uid;
        m.parent = parent;
        m.message = msg;
        m.from="from";
       
View Full Code Here

//      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

    @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

                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

            d.when = task.getWhen();

            em.persist(d);

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

    }
View Full Code Here

        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

                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

TOP

Related Classes of net.ex337.scriptus.exceptions.ScriptusRuntimeException

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.