/** * Removes a handler from the list of breakpoint handlers. * If the handler is not present in the list, the list is unchanged. * * @param handler The handler to remove. */ public void removeBreakHandler(final BreakHandler handler) { runtime.getLocker().checkThread(); breakHandlers.remove(handler); }
/** * Adds a handler to be notified when a breakpoint is hit. * * @param handler The handler to notify. */ public void addBreakHandler(final BreakHandler handler) { runtime.getLocker().checkThread(); breakHandlers.add(handler); }
/** * Runs an {@link V8Runnable} on the V8 thread. * * <b>Note: </b> This method executes synchronously, not asynchronously; * it will not return until the passed {@link V8Runnable} is done * executing. The method is also synchronized, so it will block until it * gets a chance to run. * * @param runnable {@link V8Runnable} to run. */ public synchronized void run(final V8Runnable runnable) { try { v8.getLocker().acquire(); runnable.run(v8); } finally { if ((v8 != null) && (v8.getLocker() != null) && v8.getLocker().hasLock()) { v8.getLocker().release(); } } }
/** * Create a new ConcurrentV8. A ConcurrentV8 allows multiple * threads to work with the same V8 engine by releasing * the locks between calls. */ public ConcurrentV8() { v8 = V8.createV8Runtime(); v8.getLocker().release(); }
/** * Persist an object that is currently being managed by this Manager. * * Objects that are being managed by a MemoryManager will be released * once the MemoryManager is released. If an object is persisted, it will * be remove from the MemoryManager's control and therefore will not * be released. * * @param object The object to persist */ public void persist(final V8Value object) { v8.getLocker().checkThread(); checkReleased(); references.remove(object); }
/** * Releases this Memory Manager and all V8Objects that were created while * this memory manager was active. */ public void release() { v8.getLocker().checkThread(); if (released) { return; } releasing = true; try { for (V8Value reference : references) { reference.close(); } v8.removeReferenceHandler(memoryManagerReferenceHandler); references.clear(); } finally { releasing = false; } released = true; }
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null; } } } }
} finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null;
/** * Adds a handler to be notified when a breakpoint is hit. * * @param handler The handler to notify. */ public void addBreakHandler(final BreakHandler handler) { runtime.getLocker().checkThread(); breakHandlers.add(handler); }
/** * Removes a handler from the list of breakpoint handlers. * If the handler is not present in the list, the list is unchanged. * * @param handler The handler to remove. */ public void removeBreakHandler(final BreakHandler handler) { runtime.getLocker().checkThread(); breakHandlers.remove(handler); }
/** * Persist an object that is currently being managed by this Manager. * * Objects that are being managed by a MemoryManager will be released * once the MemoryManager is released. If an object is persisted, it will * be remove from the MemoryManager's control and therefore will not * be released. * * @param object The object to persist */ public void persist(final V8Value object) { v8.getLocker().checkThread(); checkReleased(); references.remove(object); }
/** * Create a new ConcurrentV8. A ConcurrentV8 allows multiple * threads to work with the same V8 engine by releasing * the locks between calls. */ public ConcurrentV8() { v8 = V8.createV8Runtime(); v8.getLocker().release(); }
@Override public void run() { runtime = V8.createV8Runtime(); try { target.run(runtime); } finally { synchronized (this) { if (runtime.getLocker().hasLock()) { runtime.close(); runtime = null; } } } }
@Override public Object invoke(final V8Object receiver, final V8Array parameters) { v8TempRuntime = V8.createV8Runtime(); v8TempRuntime.getLocker().release(); throw new RuntimeException(); } }, "foo");
@Override public void run(final V8 runtime) { assertTrue(runtime.getLocker().hasLock()); } });
@Test public void testLockNotAquiredAfterCreation() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Test public void testLockNotAcquiredAfterExecution() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { runtime.executeScript("foo = 7;"); } }); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }