private T tryParseEvent(final JsonValue jsonValue) { try { return parseEvent(jsonValue); } catch (final JsonParseException | DittoRuntimeException e) { if (system != null) { system.log().error(e, "Could not deserialize Event JSON: '{}'", jsonValue); } else { LOGGER.error("Could not deserialize Event JSON: '{}': {}", jsonValue, e.getMessage()); } return null; } }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { Identifier identifier = (Identifier) in.readObject(); int sliceIndex = in.readInt(); int totalSlices = in.readInt(); int lastSliceHashCode = in.readInt(); byte[] data = (byte[])in.readObject(); ActorRef replyTo = JavaSerializer.currentSystem().value().provider() .resolveActorRef((String) in.readObject()); messageSlice = new MessageSlice(identifier, data, sliceIndex, totalSlices, lastSliceHashCode, replyTo); }
/** * Constructs a new {@code AbstractJsonifiableWithDittoHeadersSerializer} object. */ protected AbstractJsonifiableWithDittoHeadersSerializer(final int identifier, final ExtendedActorSystem actorSystem, final Function<Object, String> manifestProvider) { this.identifier = identifier; final MappingStrategy mappingStrategy = MappingStrategy.loadMappingStrategy(actorSystem); mappingStrategies = new HashMap<>(); mappingStrategies.putAll(requireNonNull(mappingStrategy.determineStrategy(), "mapping strategy")); this.manifestProvider = requireNonNull(manifestProvider, "manifest provider"); defaultBufferSize = actorSystem.settings().config().withFallback(FALLBACK_CONF) .getBytes(CONFIG_DIRECT_BUFFER_SIZE); final int maxPoolEntries = actorSystem.settings().config().withFallback(FALLBACK_CONF) .getInt(CONFIG_DIRECT_BUFFER_POOL_LIMIT); byteBufferPool = new DirectByteBufferPool(defaultBufferSize.intValue(), maxPoolEntries); }
/** * Creates a new factory and returns the instance * * @param actorSystem the actor system to use for mapping config + dynamicAccess * @param factoryClass the factory class scanned for factory functions * @param log the log adapter used for debug and warning logs * @return the new instance */ public static DefaultMessageMapperFactory of(final ActorSystem actorSystem, final Class<?> factoryClass, final DiagnosticLoggingAdapter log) { final Config mappingConfig = actorSystem.settings().config().getConfig("ditto.connectivity.mapping"); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); return new DefaultMessageMapperFactory(mappingConfig, dynamicAccess, factoryClass, log); }
clusterExtension.system().actorSelection(path).tell(new Identify(member.address()), TypedActor.context().self()); } else if (message instanceof MemberExited) { LOG.debug("Actor at :{} is resolving topology actor for path {}", clusterExtension.selfAddress(), path); clusterExtension.system().actorSelection(path).tell(new Identify(member.address()), TypedActor.context().self()); } else if (message instanceof ActorIdentity) { LOG.debug("Received ActorIdentity message", message); clusterExtension.system().actorSelection(path).tell(new CustomIdentifyMessage(clusterExtension.selfAddress()), TypedActor.context().self()); } else if (message instanceof CustomIdentifyMessageReply) {
/** * Creates a new factory and returns the instance * * @param actorSystem the actor system to use for mapping config + dynamicAccess * @param factoryClass the factory class scanned for factory functions * @param log the log adapter used for debug and warning logs * @return the new instance */ public static DefaultMessageMapperFactory of(final ActorSystem actorSystem, final Class<?> factoryClass, final DiagnosticLoggingAdapter log) { final Config mappingConfig = actorSystem.settings().config().getConfig("ditto.connectivity.mapping"); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); return new DefaultMessageMapperFactory(mappingConfig, dynamicAccess, factoryClass, log); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { final Identifier identifier = (Identifier) in.readObject(); final int sliceIndex = in.readInt(); final MessageSliceException failure = (MessageSliceException) in.readObject(); ActorRef sendTo = JavaSerializer.currentSystem().value().provider() .resolveActorRef((String) in.readObject()); messageSliceReply = new MessageSliceReply(identifier, sliceIndex, failure, sendTo); }
private T tryParseEvent(final JsonValue jsonValue) { try { return parseEvent(jsonValue); } catch (final JsonParseException | DittoRuntimeException e) { if (system != null) { system.log().error(e, "Could not deserialize Event JSON: '{}'", jsonValue); } else { LOGGER.error("Could not deserialize Event JSON: '{}': {}", jsonValue, e.getMessage()); } return null; } }
/** * Load the configured protocol adapter provider by reflection. * Call the 1-argument constructor every subclass of {@link ProtocolAdapterProvider} should implement. * * @param actorSystem Akka actor system to perform reflection with. * @return the loaded protocol adapter provider. */ public ProtocolAdapterProvider loadProtocolAdapterProvider(final ActorSystem actorSystem) { final String className = provider(); final ClassTag<ProtocolAdapterProvider> tag = ClassTag$.MODULE$.apply(ProtocolAdapterProvider.class); final List<Tuple2<Class<?>, Object>> constructorArgs = Collections.singletonList(new Tuple2<>(getClass(), this)); final DynamicAccess dynamicAccess = ((ExtendedActorSystem) actorSystem).dynamicAccess(); final Try<ProtocolAdapterProvider> providerBox = dynamicAccess.createInstanceFor(className, JavaConverters.asScalaBuffer(constructorArgs).toList(), tag); return providerBox.get(); }
/** * Constructs a new {@code AbstractJsonifiableWithDittoHeadersSerializer} object. */ protected AbstractJsonifiableWithDittoHeadersSerializer(final int identifier, final ExtendedActorSystem actorSystem, final Function<Object, String> manifestProvider) { this.identifier = identifier; final MappingStrategy mappingStrategy = MappingStrategy.loadMappingStrategy(actorSystem); mappingStrategies = new HashMap<>(); mappingStrategies.putAll(requireNonNull(mappingStrategy.determineStrategy(), "mapping strategy")); this.manifestProvider = requireNonNull(manifestProvider, "manifest provider"); defaultBufferSize = actorSystem.settings().config().withFallback(FALLBACK_CONF) .getBytes(CONFIG_DIRECT_BUFFER_SIZE); final int maxPoolEntries = actorSystem.settings().config().withFallback(FALLBACK_CONF) .getInt(CONFIG_DIRECT_BUFFER_POOL_LIMIT); byteBufferPool = new DirectByteBufferPool(defaultBufferSize.intValue(), maxPoolEntries); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); backend = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); maxMessages = in.readInt(); final int alternatesSize = in.readInt(); alternates = new ArrayList<>(alternatesSize); for (int i = 0; i < alternatesSize; ++i) { alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject())); } }
@Nullable private Event tryToCreateEventFrom(final JsonValue json) { try { return createEventFrom(json); } catch (final JsonParseException | DittoRuntimeException e) { final String message = MessageFormat.format("Could not deserialize ThingEvent JSON: ''{0}''", json); if (system != null) { system.log().error(e, message); } else { LOGGER.error(message, e); } return null; } }
/** * Loads the {@link MappingStrategy} in the passed ActorSystem this is running in by looking up the config key * {@value CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION}. * * @param actorSystem the ActorSystem we are running in. * @return the resolved MappingStrategy. */ static MappingStrategy loadMappingStrategy(final ActorSystem actorSystem) { // load via config the class implementing MappingStrategy: final String mappingStrategyClass = actorSystem.settings().config().getString(CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION); final ClassTag<MappingStrategy> tag = scala.reflect.ClassTag$.MODULE$.apply(MappingStrategy.class); final List<Tuple2<Class<?>, Object>> constructorArgs = new ArrayList<>(); final Try<MappingStrategy> mappingStrategy = ((ExtendedActorSystem) actorSystem).dynamicAccess().createInstanceFor(mappingStrategyClass, JavaConversions.asScalaBuffer(constructorArgs).toList(), tag); return mappingStrategy.get(); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); backend = JavaSerializer.currentSystem().value().provider().resolveActorRef(in.readUTF()); final int backendsSize = in.readInt(); if (backendsSize < 1) { throw new IOException("Illegal number of backends " + backendsSize); } alternates = new ArrayList<>(backendsSize); for (int i = 0; i < backendsSize; ++i) { alternates.add(ActorSelection.apply(ActorRef.noSender(), (String)in.readObject())); } }
@Nullable private PolicyEvent tryToCreateEventFrom(final JsonValue json) { try { return createEventFrom(json); } catch (final JsonParseException | DittoRuntimeException e) { final String message = MessageFormat.format("Could not deserialize PolicyEvent JSON: ''{0}''", json); if (system != null) { system.log().error(e, message); } else { LOGGER.error(message, e); } return null; } }
/** * Loads the {@link MappingStrategy} in the passed ActorSystem this is running in by looking up the config key * {@value CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION}. * * @param actorSystem the ActorSystem we are running in. * @return the resolved MappingStrategy. */ static MappingStrategy loadMappingStrategy(final ActorSystem actorSystem) { // load via config the class implementing MappingStrategy: final String mappingStrategyClass = actorSystem.settings().config().getString(CONFIGKEY_DITTO_MAPPING_STRATEGY_IMPLEMENTATION); final ClassTag<MappingStrategy> tag = scala.reflect.ClassTag$.MODULE$.apply(MappingStrategy.class); final List<Tuple2<Class<?>, Object>> constructorArgs = new ArrayList<>(); final Try<MappingStrategy> mappingStrategy = ((ExtendedActorSystem) actorSystem).dynamicAccess().createInstanceFor(mappingStrategyClass, JavaConversions.asScalaBuffer(constructorArgs).toList(), tag); return mappingStrategy.get(); }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef((String) in.readObject()); }
@Nullable private PolicyEvent tryToCreateEventFrom(final JsonValue json) { try { return createEventFrom(json); } catch (final JsonParseException | DittoRuntimeException e) { final String message = MessageFormat.format("Could not deserialize PolicyEvent JSON: ''{0}''", json); if (system != null) { system.log().error(e, message); } else { LOGGER.error(message, e); } return null; } }
@Override public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException { super.readExternal(in); replyTo = JavaSerializer.currentSystem().value().provider().resolveActorRef(in.readUTF()); }
@Nullable private Event tryToCreateEventFrom(final JsonValue json) { try { return createEventFrom(json); } catch (final JsonParseException | DittoRuntimeException e) { final String message = MessageFormat.format("Could not deserialize ThingEvent JSON: ''{0}''", json); if (system != null) { system.log().error(e, message); } else { LOGGER.error(message, e); } return null; } }