/** * 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); }
void checkThread() { locker.checkThread(); if (isReleased()) { throw new Error("Runtime disposed error"); } }
/** * 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); }
/** * Release the lock if it's currently held by the calling thread. * If the current thread does not hold the lock, and error will be * thrown. If no thread holds the lock then nothing will happen. */ public synchronized void release() { if ((released && (thread == null)) || runtime.isReleased()) { return; } checkThread(); runtime.releaseLock(runtime.getV8RuntimePtr()); thread = null; released = true; }
/** * 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; }
void checkThread() { locker.checkThread(); if (isReleased()) { throw new Error("Runtime disposed error"); } }
/** * 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); }
@Override public void run() { try { v8Locker.checkThread(); } catch (Error e) { assertTrue(e.getMessage().startsWith("Invalid V8 thread access")); passed = true; } } });
/** * 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; }
/** * Release the lock if it's currently held by the calling thread. * If the current thread does not hold the lock, and error will be * thrown. If no thread holds the lock then nothing will happen. */ public synchronized void release() { if ((released && (thread == null)) || runtime.isReleased()) { return; } checkThread(); runtime.releaseLock(runtime.getV8RuntimePtr()); thread = null; released = true; }
@Test public void testAcquireOnCreation() { V8Locker v8Locker = new V8Locker(v8); v8Locker.checkThread(); }
@Test public void testCannotUseReleasedLocker() { V8Locker v8Locker = new V8Locker(v8); v8Locker.release(); try { v8Locker.checkThread(); } catch (Error e) { assertTrue(e.getMessage().startsWith("Invalid V8 thread access")); return; } fail("Expected exception"); }
@Test public void testAcquireLocker() { V8Locker v8Locker = new V8Locker(v8); v8Locker.release(); v8Locker.acquire(); v8Locker.checkThread(); }
/** * Release the lock if it's currently held by the calling thread. * If the current thread does not hold the lock, and error will be * thrown. */ public synchronized void release() { checkThread(); thread = null; }
@Test public void testTryAcquireLocker_True() { V8Locker v8Locker = new V8Locker(v8); v8Locker.release(); boolean result = v8Locker.tryAcquire(); assertTrue(result); v8Locker.checkThread(); }
/** * 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); }
/** * 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); }