use of joynr.SubscriptionStop in project joynr by bmwcarit.
the class SerializationTest method serializeSubscriptionStop.
@Test
public void serializeSubscriptionStop() throws JsonGenerationException, JsonMappingException, IOException {
SubscriptionStop stop = new SubscriptionStop("testID");
String writeValueAsString = objectMapper.writeValueAsString(stop);
System.out.println(writeValueAsString);
SubscriptionStop receivedStop = objectMapper.readValue(writeValueAsString, SubscriptionStop.class);
Assert.assertEquals(stop, receivedStop);
}
use of joynr.SubscriptionStop in project joynr by bmwcarit.
the class DispatcherImpl method messageArrived.
@Override
public void messageArrived(final ImmutableMessage message) {
if (message == null) {
logger.error("received message was null");
return;
}
if (!message.isTtlAbsolute()) {
logger.error("received message with relative ttl (not supported)");
return;
}
final long expiryDate = message.getTtlMs();
final Map<String, String> customHeaders = message.getCustomHeaders();
if (DispatcherUtils.isExpired(expiryDate)) {
logger.debug("TTL expired, discarding message : {}", message);
return;
}
String payload;
try {
payload = new String(message.getUnencryptedBody(), Charsets.UTF_8);
} catch (EncodingException e) {
logger.error("Error reading SMRF message. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", new Object[] { message.getSender(), message.getRecipient(), message.getId(), e.getMessage() });
return;
}
String type = message.getType();
try {
if (Message.VALUE_MESSAGE_TYPE_REPLY.equals(type)) {
Reply reply = objectMapper.readValue(payload, Reply.class);
logger.trace("Parsed reply from message payload :" + payload);
handle(reply);
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REPLY.equals(type)) {
SubscriptionReply subscriptionReply = objectMapper.readValue(payload, SubscriptionReply.class);
logger.trace("Parsed subscription reply from message payload :" + payload);
handle(subscriptionReply);
} else if (Message.VALUE_MESSAGE_TYPE_REQUEST.equals(type)) {
final Request request = objectMapper.readValue(payload, Request.class);
request.setCreatorUserId(message.getCreatorUserId());
request.setContext(message.getContext());
logger.trace("Parsed request from message payload :" + payload);
handle(request, message.getSender(), message.getRecipient(), expiryDate, customHeaders, message.isCompressed());
} else if (Message.VALUE_MESSAGE_TYPE_ONE_WAY.equals(type)) {
OneWayRequest oneWayRequest = objectMapper.readValue(payload, OneWayRequest.class);
oneWayRequest.setCreatorUserId(message.getCreatorUserId());
oneWayRequest.setContext(message.getContext());
logger.trace("Parsed one way request from message payload :" + payload);
handle(oneWayRequest, message.getRecipient(), expiryDate);
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST.equals(type) || Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST.equals(type)) {
SubscriptionRequest subscriptionRequest = objectMapper.readValue(payload, SubscriptionRequest.class);
logger.trace("Parsed subscription request from message payload :" + payload);
handle(subscriptionRequest, message.getSender(), message.getRecipient());
} else if (Message.VALUE_MESSAGE_TYPE_SUBSCRIPTION_STOP.equals(type)) {
SubscriptionStop subscriptionStop = objectMapper.readValue(payload, SubscriptionStop.class);
logger.trace("Parsed subscription stop from message payload :" + payload);
handle(subscriptionStop);
} else if (Message.VALUE_MESSAGE_TYPE_PUBLICATION.equals(type)) {
SubscriptionPublication publication = objectMapper.readValue(payload, SubscriptionPublication.class);
logger.trace("Parsed publication from message payload :" + payload);
handle(publication);
} else if (Message.VALUE_MESSAGE_TYPE_MULTICAST.equals(type)) {
MulticastPublication multicastPublication = objectMapper.readValue(payload, MulticastPublication.class);
logger.trace("Parsed multicast publication from message payload: {}", payload);
handle(multicastPublication);
}
} catch (IOException e) {
logger.error("Error parsing payload. msgId: {}. from: {} to: {}. Reason: {}. Discarding joynr message.", message.getId(), message.getSender(), message.getRecipient(), e.getMessage());
return;
}
}
use of joynr.SubscriptionStop in project joynr by bmwcarit.
the class SubscriptionManagerImpl method unregisterSubscription.
@Override
public void unregisterSubscription(String fromParticipantId, Set<DiscoveryEntryWithMetaInfo> toDiscoveryEntries, String subscriptionId, MessagingQos qosSettings) {
PubSubState subscriptionState = subscriptionStates.get(subscriptionId);
if (subscriptionState != null) {
logger.trace("Called unregister / unsubscribe on subscription id= " + subscriptionId);
removeSubscription(subscriptionId);
} else {
logger.trace("Called unregister on a non/no longer existent subscription, used id= " + subscriptionId);
}
SubscriptionStop subscriptionStop = new SubscriptionStop(subscriptionId);
dispatcher.sendSubscriptionStop(fromParticipantId, toDiscoveryEntries, subscriptionStop, new MessagingQos(qosSettings));
}
use of joynr.SubscriptionStop in project joynr by bmwcarit.
the class TtlUpliftTest method testTtlUpliftMs_SubscriptionStop.
@Test
public void testTtlUpliftMs_SubscriptionStop() {
SubscriptionStop subscriptionStop = new SubscriptionStop();
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
MutableMessage message = messageFactoryWithTtlUplift.createSubscriptionStop(fromParticipantId, toParticipantId, subscriptionStop, messagingQos);
long expiryDateValue = expiryDate.getValue() + TTL_UPLIFT_MS;
MutableMessageFactoryTest.assertExpiryDateEquals(expiryDateValue, message);
}
Aggregations