@Override protected Object clone() throws TCloneNotSupportedException { if (!(this instanceof TCloneable) && Platform.getPlatformObject(this).getPlatformClass().getMetadata().getArrayItem() == null) { throw new TCloneNotSupportedException(); } Object result = Platform.clone(this); Platform.getPlatformObject(result).setId(Platform.nextObjectId()); return result; }
@Override public void interrupted() { if (performed) { return; } performed = true; if (timerId >= 0) { Platform.killSchedule(timerId); timerId = -1; } Platform.postpone(() -> callback.error(new TInterruptedException())); }
@Sync static void monitorExit(final TObject o, int count) { if (o.isEmptyMonitor() || o.monitor.owner != TThread.currentThread()) { throw new TIllegalMonitorStateException(); } o.monitor.count -= count; if (o.monitor.count > 0) { return; } o.monitor.owner = null; if (!o.monitor.enteringThreads.isEmpty()) { Platform.postpone( () -> { if (o.isEmptyMonitor() || o.monitor.owner != null) { return; } if (!o.monitor.enteringThreads.isEmpty()) { o.monitor.enteringThreads.remove().run(); } }); } else { o.isEmptyMonitor(); } }
public final void waitImpl(long timeout, int nanos, final AsyncCallback<Void> callback) { final NotifyListenerImpl listener = new NotifyListenerImpl(this, callback, monitor.count); monitor.notifyListeners.add(listener); if (timeout > 0 || nanos > 0) { listener.timerId = Platform.schedule( listener, timeout >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) timeout); } monitorExit(this, monitor.count); }
@Override public void run() { if (performed) { return; } performed = true; if (timerId >= 0) { Platform.killSchedule(timerId); timerId = -1; } TThread.setCurrentThread(currentThread); monitorEnterWait(obj, lockCount, callback); }
@Sync @Rename("notifyAll") public final void notifyAll0() { if (!holdsLock(this)) { throw new TIllegalMonitorStateException(); } PlatformQueue<NotifyListener> listeners = monitor.notifyListeners; while (!listeners.isEmpty()) { NotifyListener listener = listeners.remove(); if (!listener.expired()) { Platform.postpone(listener); } } }
public Monitor() { this.owner = TThread.currentThread(); enteringThreads = Platform.createQueue(); notifyListeners = Platform.createQueue(); }
int identity() { return Platform.getPlatformObject(this).getId(); }
@Rename("getClass") public final TClass<?> getClass0() { return TClass.getClass(Platform.getPlatformObject(this).getPlatformClass()); }
@Rename("<init>") private void init() { Platform.getPlatformObject(this).setId(Platform.nextObjectId()); }