use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.
the class SubscriptionManagerImpl method handleBroadcastPublication.
@Override
public void handleBroadcastPublication(String subscriptionId, Object[] broadcastValues) {
BroadcastSubscriptionListener broadcastSubscriptionListener = getBroadcastSubscriptionListener(subscriptionId);
try {
Class<?>[] broadcastTypes = getParameterTypesForBroadcastPublication(broadcastValues);
Method receive = broadcastSubscriptionListener.getClass().getDeclaredMethod("onReceive", broadcastTypes);
if (!receive.isAccessible()) {
receive.setAccessible(true);
}
logger.debug("SUBSCRIPTION notify listener: subscriptionId: {}, broadcastValue: {}", subscriptionId, broadcastValues);
receive.invoke(broadcastSubscriptionListener, broadcastValues);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
logger.error("Broadcast publication could not be processed", e);
}
}
use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.
the class SubscriptionManagerTest method testHandleSubscriptionReplyWithSuccessWithBroadcastListener.
@Test
public void testHandleSubscriptionReplyWithSuccessWithBroadcastListener() {
SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId);
@SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
subscriptionFutureMap.put(subscriptionId, futureMock);
BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
subscriptionManager.handleSubscriptionReply(subscriptionReply);
verify(futureMock).onSuccess(eq(subscriptionId));
verify(broadcastListener).onSubscribed(eq(subscriptionId));
}
use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.
the class SubscriptionManagerTest method registerBroadcastSubscription.
@Test
public void registerBroadcastSubscription() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
String broadcastName = "broadcastName";
BroadcastSubscriptionListener broadcastSubscriptionListener = mock(LocationUpdateBroadcastListener.class);
BroadcastSubscribeInvocation subscriptionRequest = new BroadcastSubscribeInvocation(broadcastName, broadcastSubscriptionListener, onChangeQos, future);
subscriptionManager.registerBroadcastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
subscriptionId = subscriptionRequest.getSubscriptionId();
verify(broadcastSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(broadcastSubscriptionListener));
verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
verify(cleanupScheduler).schedule(Mockito.any(Runnable.class), Mockito.eq(onChangeQos.getExpiryDateMs()), Mockito.eq(TimeUnit.MILLISECONDS));
verify(subscriptionEndFutures, Mockito.times(1)).put(Mockito.eq(subscriptionId), Mockito.any(ScheduledFuture.class));
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.
the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithBroadcastListener.
@Test
public void testHandleSubscriptionReplyWithErrorWithBroadcastListener() {
SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
@SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
subscriptionFutureMap.put(subscriptionId, futureMock);
BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
subscriptionManager.handleSubscriptionReply(subscriptionReply);
verify(futureMock).onFailure(eq(subscriptionError));
verify(broadcastListener).onError(eq(subscriptionError));
}
use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.
the class SubscriptionManagerTest method testRegisterMulticastSubscription.
@SuppressWarnings("unchecked")
private void testRegisterMulticastSubscription(String subscriptionId, String... partitions) throws Exception {
Method method = TestMulticastSubscriptionInterface.class.getMethod("subscribeToMyMulticast", new Class[0]);
BroadcastSubscriptionListener listener = spy(new BroadcastSubscriptionListener() {
@Override
public void onError(SubscriptionException error) {
}
@Override
public void onSubscribed(String subscriptionId) {
}
@SuppressWarnings("unused")
public void onReceive() {
}
});
SubscriptionQos subscriptionQos = mock(MulticastSubscriptionQos.class);
Object[] args;
if (subscriptionId == null) {
args = new Object[] { listener, subscriptionQos, partitions };
} else {
args = new Object[] { subscriptionId, listener, subscriptionQos, partitions };
}
String multicastId = MulticastIdUtil.createMulticastId(toParticipantId, "myMulticast", partitions);
Set<String> subscriptionIdSet = new HashSet<>();
Pattern multicastIdPattern = Pattern.compile(multicastId);
multicastSubscribersDirectory.put(multicastIdPattern, subscriptionIdSet);
when(multicastWildcardRegexFactory.createIdPattern(multicastId)).thenReturn(multicastIdPattern);
MulticastSubscribeInvocation invocation = new MulticastSubscribeInvocation(method, args, future);
DiscoveryEntryWithMetaInfo toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
subscriptionManager.registerMulticastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), invocation);
verify(multicastSubscribersDirectory).put(any(Pattern.class), anySet());
assertEquals(1, subscriptionIdSet.size());
if (subscriptionId != null) {
assertEquals(subscriptionId, subscriptionIdSet.iterator().next());
}
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Aggregations