Ejemplo n.º 1
0
  private void listen(int portNumber) throws IOException {
    Socket s;
    Thread t;

    PySystemState.initialize();

    try {
      sock = new ServerSocket(portNumber);
    } catch (IOException e) {
      System.err.println("Could not listen on port: 4444.");
      return;
    }

    while (true) {
      s = sock.accept();

      synchronized (lock) {
        if (shutdownRequested) {
          break;
        }
      }

      t = new JythonServerWorker(s, new JythonServerProtocol(s));
      t.start();
    }

    sock.close();
  }
  @Test
  public void testCreateInstrumentedProxy() throws Exception {
    final GrinderProperties properties = new GrinderProperties();
    final DCRContext context = DCRContextImplementation.create(null);

    final List<Instrumenter> instrumenters =
        new JythonScriptEngineService(properties, context, m_pyScript).createInstrumenters();

    assertEquals(1, instrumenters.size());

    final Instrumenter instrumenter = instrumenters.get(0);

    assertEquals("traditional Jython instrumenter", instrumenter.getDescription());

    final Object foo = new Object();

    PySystemState.initialize();

    final PyObject proxy = (PyObject) instrumenter.createInstrumentedProxy(m_test, m_recorder, foo);

    assertSame(proxy.__getattr__("__target__").__tojava__(Object.class), foo);

    try {
      instrumenter.createInstrumentedProxy(m_test, m_recorder, new PyObject());
      fail("Expected NotWrappableTypeException");
    } catch (NotWrappableTypeException e) {
    }
  }
 {
   PySystemState.initialize();
 }
Ejemplo n.º 4
0
 /**
  * Initializes the jython runtime. This should only be called once, and should be called before
  * any other python objects are created (including a PythonInterpreter).
  *
  * @param preProperties A set of properties. Typically System.getProperties() is used.
  * @param postProperties An other set of properties. Values like python.home, python.path and all
  *     other values from the registry files can be added to this property set. PostProperties will
  *     override system properties and registry properties.
  * @param argv Command line argument. These values will assigned to sys.argv.
  */
 public static void initialize(
     Properties preProperties, Properties postProperties, String[] argv) {
   PySystemState.initialize(preProperties, postProperties, argv);
 }