@Test public void testDefaultTriggerWithSessionWindow() throws Exception { ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining( Sessions.withGapDuration(Duration.millis(10)), DefaultTrigger.<IntervalWindow>of(), AccumulationMode.DISCARDING_FIRED_PANES, Duration.millis(100)); tester.injectElements( TimestampedValue.of(1, new Instant(1)), TimestampedValue.of(2, new Instant(9))); // no output, because we merged into the [9-19) session tester.advanceInputWatermark(new Instant(10)); assertThat(tester.extractOutput(), Matchers.emptyIterable()); tester.injectElements( TimestampedValue.of(3, new Instant(15)), TimestampedValue.of(4, new Instant(30))); tester.advanceInputWatermark(new Instant(100)); assertThat( tester.extractOutput(), Matchers.contains( isSingleWindowedValue(Matchers.containsInAnyOrder(1, 2, 3), 1, 1, 25), isSingleWindowedValue(Matchers.contains(4), 30, 30, 40))); assertFalse(tester.isMarkedFinished(new IntervalWindow(new Instant(1), new Instant(25)))); assertFalse(tester.isMarkedFinished(new IntervalWindow(new Instant(30), new Instant(40)))); tester.assertHasOnlyGlobalAndPaneInfoFor( new IntervalWindow(new Instant(1), new Instant(25)), new IntervalWindow(new Instant(30), new Instant(40))); }
public static void remove(File sourceDirectoryRoot) { Session session = sourceDirectoryRootToSessionMap.remove(sourceDirectoryRoot); if (session == null) { throw new RuntimeException("no such session:" + sourceDirectoryRoot.getAbsolutePath()); } Sessions.remove(session.getSessionID()); }
/** * Unwatches an event. * * @throws IOException I/O exception */ private void unwatch() throws IOException { final String name = in.readString(); final Sessions s = context.events.get(name); final boolean ok = s != null && s.contains(this); final String message; if (ok) { s.remove(this); message = UNWATCHING_EVENT_X; } else if (s == null) { message = EVENT_UNKNOWN_X; } else { message = EVENT_NOT_WATCHED_X; } info(Util.info(message, name), ok); out.flush(); }
/** * Watches an event. * * @throws IOException I/O exception */ private void watch() throws IOException { server.initEvents(); // initialize server-based event handling if (!events) { out.writeString(Integer.toString(context.mprop.num(MainProp.EVENTPORT))); out.writeString(Long.toString(getId())); out.flush(); events = true; } final String name = in.readString(); final Sessions s = context.events.get(name); final boolean ok = s != null && !s.contains(this); final String message; if (ok) { s.add(this); message = WATCHING_EVENT_X; } else if (s == null) { message = EVENT_UNKNOWN_X; } else { message = EVENT_WATCHED_X; } info(Util.info(message, name), ok); }
/** Exits the session. */ public synchronized void quit() { running = false; if (log != null) log.write(this, "LOGOUT " + context.user.name, OK); // wait until running command was stopped if (command != null) { command.stop(); while (command != null) Performance.sleep(50); } context.delete(this); try { new Close().execute(context); socket.close(); if (events) { esocket.close(); // remove this session from all events in pool for (final Sessions s : context.events.values()) s.remove(this); } } catch (final Exception ex) { if (log != null) log.write(ex.getMessage()); Util.stack(ex); } }
public static synchronized Session create( File sourceDirectoryRoot, NetworkPeer peer, TaskExecutorEnv localTaskExecutorEnv, SessionThreadManager sessionThreadManager) throws IOException, TaskException { Session session = new MarkReaderSession( sourceDirectoryRoot, peer, localTaskExecutorEnv, sessionThreadManager); Sessions.add(session); sourceDirectoryRootToSessionMap.put(sourceDirectoryRoot, session); try { Thread.sleep(1); } catch (InterruptedException ignore) { } return session; }
@Test public void testDefaultTriggerWithContainedSessionWindow() throws Exception { ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining( Sessions.withGapDuration(Duration.millis(10)), DefaultTrigger.<IntervalWindow>of(), AccumulationMode.DISCARDING_FIRED_PANES, Duration.millis(100)); tester.injectElements( TimestampedValue.of(1, new Instant(1)), TimestampedValue.of(2, new Instant(9)), TimestampedValue.of(3, new Instant(7))); tester.advanceInputWatermark(new Instant(20)); Iterable<WindowedValue<Iterable<Integer>>> extractOutput = tester.extractOutput(); assertThat( extractOutput, Matchers.contains(isSingleWindowedValue(Matchers.containsInAnyOrder(1, 2, 3), 1, 1, 19))); tester.assertHasOnlyGlobalAndPaneInfoFor(new IntervalWindow(new Instant(1), new Instant(19))); }
/** * Tests that if the EOW is finished in both as well as the merged window, then it is finished in * the merged result. * * <p>Because windows are discarded when a trigger finishes, we need to embed this in a sequence * in order to check that it is re-activated. So this test is potentially sensitive to other * triggers' correctness. */ @Test public void testEarlyAndLateOnMergeAlreadyFinished() throws Exception { tester = TriggerTester.forTrigger( AfterWatermark.<IntervalWindow>pastEndOfWindow() .withEarlyFirings(AfterPane.<IntervalWindow>elementCountAtLeast(100)) .withLateFirings(AfterPane.<IntervalWindow>elementCountAtLeast(1)), Sessions.withGapDuration(Duration.millis(10))); tester.injectElements(1); tester.injectElements(5); IntervalWindow firstWindow = new IntervalWindow(new Instant(1), new Instant(11)); IntervalWindow secondWindow = new IntervalWindow(new Instant(5), new Instant(15)); IntervalWindow mergedWindow = new IntervalWindow(new Instant(1), new Instant(15)); // Finish the AfterWatermark.pastEndOfWindow() bit of the trigger in both windows tester.advanceInputWatermark(new Instant(15)); assertTrue(tester.shouldFire(firstWindow)); assertTrue(tester.shouldFire(secondWindow)); tester.fireIfShouldFire(firstWindow); tester.fireIfShouldFire(secondWindow); // Confirm that we are on the late trigger by probing assertFalse(tester.shouldFire(firstWindow)); assertFalse(tester.shouldFire(secondWindow)); tester.injectElements(1); tester.injectElements(5); assertTrue(tester.shouldFire(firstWindow)); assertTrue(tester.shouldFire(secondWindow)); tester.fireIfShouldFire(firstWindow); tester.fireIfShouldFire(secondWindow); // Merging should leave it on the late trigger tester.mergeWindows(); // Confirm that we are on the late trigger by probing assertFalse(tester.shouldFire(mergedWindow)); tester.injectElements(1); assertTrue(tester.shouldFire(mergedWindow)); }
/** * Tests that the trigger rewinds to be non-finished in the merged window. * * <p>Because windows are discarded when a trigger finishes, we need to embed this in a sequence * in order to check that it is re-activated. So this test is potentially sensitive to other * triggers' correctness. */ @Test public void testOnMergeRewinds() throws Exception { tester = TriggerTester.forTrigger( AfterEach.inOrder( AfterWatermark.<IntervalWindow>pastEndOfWindow(), Repeatedly.forever(AfterPane.<IntervalWindow>elementCountAtLeast(1))), Sessions.withGapDuration(Duration.millis(10))); tester.injectElements(1); tester.injectElements(5); IntervalWindow firstWindow = new IntervalWindow(new Instant(1), new Instant(11)); IntervalWindow secondWindow = new IntervalWindow(new Instant(5), new Instant(15)); IntervalWindow mergedWindow = new IntervalWindow(new Instant(1), new Instant(15)); // Finish the AfterWatermark.pastEndOfWindow() trigger in only the first window tester.advanceInputWatermark(new Instant(11)); assertTrue(tester.shouldFire(firstWindow)); assertFalse(tester.shouldFire(secondWindow)); tester.fireIfShouldFire(firstWindow); // Confirm that we are on the second trigger by probing assertFalse(tester.shouldFire(firstWindow)); tester.injectElements(1); assertTrue(tester.shouldFire(firstWindow)); tester.fireIfShouldFire(firstWindow); // Merging should re-activate the watermark trigger in the merged window tester.mergeWindows(); // Confirm that we are not on the second trigger by probing assertFalse(tester.shouldFire(mergedWindow)); tester.injectElements(1); assertFalse(tester.shouldFire(mergedWindow)); // And confirm that advancing the watermark fires again tester.advanceInputWatermark(new Instant(15)); assertTrue(tester.shouldFire(mergedWindow)); }
@Test public void testAfterPaneWithMerging() throws Exception { Duration windowDuration = Duration.millis(10); ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining( Sessions.withGapDuration(windowDuration), AfterPane.<IntervalWindow>elementCountAtLeast(2), AccumulationMode.DISCARDING_FIRED_PANES, Duration.millis(100)); assertThat(tester.extractOutput(), Matchers.emptyIterable()); tester.injectElements( TimestampedValue.of(1, new Instant(1)), // in [1, 11) TimestampedValue.of(2, new Instant(2))); // in [2, 12) assertThat( tester.extractOutput(), Matchers.contains( WindowMatchers.isSingleWindowedValue(Matchers.containsInAnyOrder(1, 2), 1, 1, 12))); // Because we closed the previous window, we don't have it around to merge with. tester.injectElements( TimestampedValue.of(3, new Instant(7)), // in [7, 17) TimestampedValue.of(4, new Instant(8))); // in [8, 18) assertThat( tester.extractOutput(), Matchers.contains( WindowMatchers.isSingleWindowedValue(Matchers.containsInAnyOrder(3, 4), 7, 7, 18))); assertTrue(tester.isMarkedFinished(new IntervalWindow(new Instant(1), new Instant(12)))); tester.assertHasOnlyGlobalAndFinishedSetsFor( new IntervalWindow(new Instant(1), new Instant(12)), new IntervalWindow(new Instant(7), new Instant(18))); }
/** * opens an {@link ObjectContainer ObjectContainer} on the specified database file for local use. * <br> * <br> * Subsidiary calls with the same database file name will return the same {@link ObjectContainer * ObjectContainer} object.<br> * <br> * Every call to <code>openFile()</code> requires a corresponding {@link ObjectContainer#close * ObjectContainer.close}.<br> * <br> * Database files can only be accessed for readwrite access from one process (one Java VM) at one * time. All versions except for db4o mobile edition use an internal mechanism to lock the * database file for other processes. <br> * <br> * * @param databaseFileName the full path to the database file * @return an open {@link ObjectContainer ObjectContainer} * @see Configuration#readOnly * @see Configuration#encrypt * @see Configuration#password */ public static final ObjectContainer openFile(String databaseFileName) throws DatabaseFileLockedException { synchronized (Db4o.lock) { return i_sessions.open(databaseFileName); } }
static void sessionStopped(Session a_session) { i_sessions.remove(a_session); }
static void forEachSession(Visitor4 visitor) { i_sessions.forEach(visitor); }