@Test public void testClosedPoolLock() throws Exception { assertWithPool(pool -> { class X implements PoolListener { short ev = -1; @Override public void onEvent(byte factoryType, long thread, CharSequence name, short event, short segment, short position) { this.ev = event; } } X x = new X(); pool.setPoolListener(x); pool.close(); try { pool.lock("x"); Assert.fail(); } catch (PoolClosedException ignored) { } Assert.assertEquals(PoolListener.EV_POOL_CLOSED, x.ev); }); }
public boolean lock(CharSequence tableName) { checkClosed(); long thread = Thread.currentThread().getId(); Entry e = entries.get(tableName); if (e == null) { e = new Entry(clock.getTicks()); Entry other = entries.putIfAbsent(tableName, e); if (other == null) { if (lockAndNotify(thread, e, tableName)) { return true; } else { entries.remove(tableName); return false; } } else { e = other; } } if ((Unsafe.cas(e, ENTRY_OWNER, UNALLOCATED, thread) )) { closeWriter(thread, e, PoolListener.EV_LOCK_CLOSE, PoolConstants.CR_NAME_LOCK); return lockAndNotify(thread, e, tableName); } LOG.error().$("could not lock, busy [table=`").utf8(tableName).$("`, owner=").$(e.owner).$(", thread=").$(thread).$(']').$(); notifyListener(thread, tableName, PoolListener.EV_LOCK_BUSY); return false; }
WriterPool extends AbstractPool implements ResourcePool<TableWriter> { public boolean lock(CharSequence tableName) { checkClosed(); long thread = Thread.currentThread().getId(); Entry e = entries.get(tableName); if (e == null) { e = new Entry(clock.getTicks()); Entry other = entries.putIfAbsent(tableName, e); if (other == null) { if (lockAndNotify(thread, e, tableName)) { return true; } else { entries.remove(tableName); return false; } } else { e = other; } } if ((Unsafe.cas(e, ENTRY_OWNER, UNALLOCATED, thread) )) { closeWriter(thread, e, PoolListener.EV_LOCK_CLOSE, PoolConstants.CR_NAME_LOCK); return lockAndNotify(thread, e, tableName); } LOG.error().$("could not lock, busy [table=`").utf8(tableName).$("`, owner=").$(e.owner).$(", thread=").$(thread).$(']').$(); notifyListener(thread, tableName, PoolListener.EV_LOCK_BUSY); return false; } }
WriterPool extends AbstractPool implements ResourcePool<TableWriter> { public boolean lock(CharSequence tableName) { checkClosed(); long thread = Thread.currentThread().getId(); Entry e = entries.get(tableName); if (e == null) { e = new Entry(clock.getTicks()); Entry other = entries.putIfAbsent(tableName, e); if (other == null) { if (lockAndNotify(thread, e, tableName)) { return true; } else { entries.remove(tableName); return false; } } else { e = other; } } if ((Unsafe.cas(e, ENTRY_OWNER, UNALLOCATED, thread) )) { closeWriter(thread, e, PoolListener.EV_LOCK_CLOSE, PoolConstants.CR_NAME_LOCK); return lockAndNotify(thread, e, tableName); } LOG.error().$("could not lock, busy [table=`").utf8(tableName).$("`, owner=").$(e.owner).$(", thread=").$(thread).$(']').$(); notifyListener(thread, tableName, PoolListener.EV_LOCK_BUSY); return false; } WriterPool(CairoConfiguration configuration, @Nullable MessageBus messageBus); }
WriterPool extends AbstractPool implements ResourcePool<TableWriter> { public boolean lock(CharSequence tableName) { checkClosed(); long thread = Thread.currentThread().getId(); Entry e = entries.get(tableName); if (e == null) { e = new Entry(clock.getTicks()); Entry other = entries.putIfAbsent(tableName, e); if (other == null) { if (lockAndNotify(thread, e, tableName)) { return true; } else { entries.remove(tableName); return false; } } else { e = other; } } if ((Unsafe.cas(e, ENTRY_OWNER, UNALLOCATED, thread) )) { closeWriter(thread, e, PoolListener.EV_LOCK_CLOSE, PoolConstants.CR_NAME_LOCK); return lockAndNotify(thread, e, tableName); } LOG.error().$("could not lock, busy [table=`").utf8(tableName).$("`, owner=").$(e.owner).$(", thread=").$(thread).$(']').$(); notifyListener(thread, tableName, PoolListener.EV_LOCK_BUSY); return false; } WriterPool(CairoConfiguration configuration, @Nullable MessageBus messageBus); @Override TableWriter get(CharSequence tableName); boolean lock(CharSequence tableName); int getBusyCount(); int size(); void unlock(CharSequence name); void unlock(CharSequence name, @Nullable TableWriter writer); }
WriterPool extends AbstractPool implements ResourcePool<TableWriter> { public boolean lock(CharSequence tableName) { checkClosed(); long thread = Thread.currentThread().getId(); Entry e = entries.get(tableName); if (e == null) { e = new Entry(clock.getTicks()); Entry other = entries.putIfAbsent(tableName, e); if (other == null) { if (lockAndNotify(thread, e, tableName)) { return true; } else { entries.remove(tableName); return false; } } else { e = other; } } if ((Unsafe.cas(e, ENTRY_OWNER, UNALLOCATED, thread) )) { closeWriter(thread, e, PoolListener.EV_LOCK_CLOSE, PoolConstants.CR_NAME_LOCK); return lockAndNotify(thread, e, tableName); } LOG.error().$("could not lock, busy [table=`").utf8(tableName).$("`, owner=").$(e.owner).$(", thread=").$(thread).$(']').$(); notifyListener(thread, tableName, PoolListener.EV_LOCK_BUSY); return false; } WriterPool(CairoConfiguration configuration, @Nullable MessageBus messageBus); @Override TableWriter get(CharSequence tableName); boolean lock(CharSequence tableName); int getBusyCount(); int size(); void unlock(CharSequence name); void unlock(CharSequence name, @Nullable TableWriter writer);  }