@Ignore @Test public void testEventWait() { final TelegesisFrameHandler frameHandler = new TelegesisFrameHandler(null); final List<TelegesisEvent> eventCapture = new ArrayList<TelegesisEvent>(); Thread waitThread = new Thread() { @Override public void run() { eventCapture.add(frameHandler.eventWait(TelegesisSleepyDeviceAnnounceEvent.class)); synchronized (eventCapture) { eventCapture.notify(); } } }; waitThread.start(); TelegesisEvent eventOk = new TelegesisSleepyDeviceAnnounceEvent(); TelegesisEvent eventNOk = new TelegesisNetworkLostEvent(); try { Method privateMethod; try { privateMethod = TelegesisFrameHandler.class.getDeclaredMethod("notifyEventReceived", new Class[] { TelegesisEvent.class }); privateMethod.setAccessible(true); privateMethod.invoke(frameHandler, eventNOk); privateMethod.invoke(frameHandler, eventOk); } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } synchronized (eventCapture) { eventCapture.wait(1000); } } catch (InterruptedException e) { e.printStackTrace(); } assertEquals(1, eventCapture.size()); }
public TelegesisEvent eventWait(final Class<?> eventClass) { Future<TelegesisEvent> future = waitEventAsync(eventClass); try { return future.get(transactionTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Telegesis interrupted in eventWait {}", eventClass); future.cancel(true); return null; } }
TelegesisFrameHandler { public TelegesisEvent eventWait(final Class<?> eventClass) { Future<TelegesisEvent> future = waitEventAsync(eventClass); try { return future.get(transactionTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Telegesis interrupted in eventWait {}", eventClass); future.cancel(true); return null; } } }
TelegesisFrameHandler { public TelegesisEvent eventWait(final Class<?> eventClass) { Future<TelegesisEvent> future = waitEventAsync(eventClass); try { return future.get(transactionTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Telegesis interrupted in eventWait {}", eventClass); future.cancel(true); return null; } } TelegesisFrameHandler(ZigBeeDongleTelegesis zigBeeDongleTelegesis); }
TelegesisFrameHandler { public TelegesisEvent eventWait(final Class<?> eventClass) { Future<TelegesisEvent> future = waitEventAsync(eventClass); try { return future.get(transactionTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Telegesis interrupted in eventWait {}", eventClass); future.cancel(true); return null; } } TelegesisFrameHandler(ZigBeeDongleTelegesis zigBeeDongleTelegesis); void start(final ZigBeePort serialPort); void setClosing(); void close(); boolean isAlive(); void queueFrame(TelegesisCommand request); void setCommandTimeout(int commandTimeout); void setTransactionTimeout(int transactionTimeout); void addEventListener(TelegesisEventListener listener); void removeEventListener(TelegesisEventListener listener); Future<TelegesisCommand> sendRequestAsync(final TelegesisCommand command); TelegesisStatusCode sendRequest(final TelegesisCommand command); Future<TelegesisEvent> waitEventAsync(final Class<?> eventClass); TelegesisEvent eventWait(final Class<?> eventClass); }
TelegesisFrameHandler { public TelegesisEvent eventWait(final Class<?> eventClass) { Future<TelegesisEvent> future = waitEventAsync(eventClass); try { return future.get(transactionTimeout, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.debug("Telegesis interrupted in eventWait {}", eventClass); future.cancel(true); return null; } } TelegesisFrameHandler(ZigBeeDongleTelegesis zigBeeDongleTelegesis); void start(final ZigBeePort serialPort); void setClosing(); void close(); boolean isAlive(); void queueFrame(TelegesisCommand request); void setCommandTimeout(int commandTimeout); void setTransactionTimeout(int transactionTimeout); void addEventListener(TelegesisEventListener listener); void removeEventListener(TelegesisEventListener listener); Future<TelegesisCommand> sendRequestAsync(final TelegesisCommand command); TelegesisStatusCode sendRequest(final TelegesisCommand command); Future<TelegesisEvent> waitEventAsync(final Class<?> eventClass); TelegesisEvent eventWait(final Class<?> eventClass);  }