String toString(Object obj) { if (obj instanceof String) { return (String) obj; } if (obj instanceof AbstractActor) { final RemoteReference ref = RemoteReference.from((AbstractActor) obj); return RemoteReference.getInterfaceClass(ref).getSimpleName() + ":" + RemoteReference.getId(ref); } if (obj instanceof RemoteReference) { return RemoteReference.getInterfaceClass((RemoteReference<?>) obj).getSimpleName() + ":" + RemoteReference.getId((RemoteReference<?>) obj); } return String.valueOf(obj); }
@SuppressWarnings("unchecked") public static <R> Class<R> getInterfaceClass(final AbstractActor reference) { return from(reference)._interfaceClass(); }
@Override public String toString() { final StringBuilder output = new StringBuilder(); output.append("RemoteReference["); if(address != null) { output.append("address="); output.append(address); output.append(", "); } if(id != null) { output.append("id="); output.append(id.toString()); output.append(", "); } output.append("interfaceId="); output.append(_interfaceId()); output.append(", "); if(_interfaceClass() != null) { output.append("interfaceName="); output.append(_interfaceClass().getName()); output.append(", "); } output.deleteCharAt(output.length() - 2); output.append("]"); return output.toString(); }
@Override public Object copy(final Kryo kryo, final Object original) { if (original instanceof RemoteReference) { final RemoteReference<?> remoteReference = (RemoteReference<?>) original; if (RemoteReference.getRuntime(remoteReference) != null) { return DefaultDescriptorFactory.get().getReference(null, RemoteReference.getAddress(remoteReference), RemoteReference.getInterfaceClass(remoteReference), RemoteReference.getId(remoteReference)); } } return original; }
if (method == null) method = DefaultDescriptorFactory.get().getInvoker(RemoteReference.getInterfaceClass(toReference)).getMethod(invocation.getMethodId()); String to = TestLogger.wrap(RemoteReference.getInterfaceClass(toReference).getSimpleName() + ":" + RemoteReference.getId(toReference), 32, "\\n", false);
@Override public Logger getLogger(final Object object) { if (object instanceof Actor) { return getLogger(RemoteReference.getInterfaceClass(RemoteReference.from((Actor) object)).getName()); } if (object instanceof Class) { return getLogger(((Class) object).getName()); } if (object instanceof String) { return getLogger((String) object); } if (object != null) { return getLogger(object.getClass()); } return getLogger((String) null); } }
@Override public void serialize(final Object value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { final NodeAddress address = RemoteReference.getAddress((RemoteReference<?>) value); final Object actorId = RemoteReference.getId((RemoteReference<?>) value); jgen.writeString((address != null ? address.asUUID() : "") + "/" + actorId); }
public LocalObjectEntry findLocalActor(Actor actor) { if (actor instanceof AbstractActor) { return (LocalObjectEntry) ((AbstractActor) actor).activation; } return localObjects.get(RemoteReference.from(actor)); }
public Task<?> writeInvocation(final HandlerContext ctx, Invocation invocation) { final Addressable toReference = invocation.getToReference(); final RemoteReference<?> actorReference = (RemoteReference<?>) toReference; final NodeAddress toNode = invocation.getToNode(); Map<String, Object> actualHeaders = null; if (invocation.getHeaders() != null) { actualHeaders = new HashMap<>(); actualHeaders.putAll(invocation.getHeaders()); } final Message message = new Message() .withMessageType(invocation.isOneWay() ? MessageDefinitions.ONE_WAY_MESSAGE : MessageDefinitions.REQUEST_MESSAGE) .withToNode(toNode) .withFromNode(invocation.getFromNode()) .withHeaders(actualHeaders) .withInterfaceId(actorReference._interfaceId()) .withMessageId(invocation.getMessageId()) .withMethodId(invocation.getMethodId()) .withObjectId(RemoteReference.getId(actorReference)) .withPayload(invocation.getParams()) .withReferenceAddress(invocation.getToReference().address); if (logger.isTraceEnabled()) { logger.trace("sending message to " + toReference); } return writeMessage(ctx, message); }
protected String getIdentity(final RemoteReference<?> reference) { return String.valueOf(RemoteReference.getId(reference)); }
/** * Utility method used by the framework and framework extensions to retrieve the Actor or ActorObserver * interface implemented by this reference. * * <p>This is not exposed as an instance method to avoid clashes with the methods from implemented interfaces</p> * * @param reference the reference being inspected * @return the implemented interface */ public static <R> Class<R> getInterfaceClass(final RemoteReference<R> reference) { return reference._interfaceClass(); }
private boolean shouldRemove(final ActorBaseEntry<?> actorEntry, final Set<ActorBaseEntry<?>> toRemove) final Class<?> interfaceClass = RemoteReference.getInterfaceClass(actorEntry.getRemoteReference());
/** * Utility method used by the framework and framework extensions to retrieve the integer identifier of * the Actor or ActorObserver interface implemented by this reference. * * <p>This is not exposed as an instance method to avoid clashes with the methods from implemented interfaces</p> * * @param reference the reference being inspected * @return the implemented interface id */ public static int getInterfaceId(final RemoteReference<?> reference) { return reference._interfaceId(); }
public Task<NodeAddress> locateActor(final RemoteReference reference, final boolean forceActivation) { final NodeAddress address = RemoteReference.getAddress(reference); if (address != null) { // don't need to call the node call the node to check. // checks should be explicit. return activeNodes.containsKey(address) ? Task.fromValue(address) : Task.fromValue(null); } return (forceActivation) ? locateAndActivateActor(reference) : locateActiveActor(reference); }
@Override public Object copy(final Kryo kryo, final Object original) { if (original instanceof AbstractActor) { return RemoteReference.from((AbstractActor) original); } if (original instanceof RemoteReference) { final RemoteReference<?> remoteReference = (RemoteReference<?>) original; if (RemoteReference.getRuntime(remoteReference) != null) { return DefaultDescriptorFactory.get().getReference(null, RemoteReference.getAddress(remoteReference), RemoteReference.getInterfaceClass(remoteReference), RemoteReference.getId(remoteReference)); } return original; } if (original == null) { return null; } throw new IllegalArgumentException("Invalid type for " + original); }
public String generateDocumentId(final RemoteReference<?> reference) { final Class<?> referenceClass = RemoteReference.getInterfaceClass(reference); final String idDecoration = referenceClass.getSimpleName(); final String documentId = String.format( "%s%s%s", idDecoration, "/", String.valueOf(RemoteReference.getId(reference))); return documentId; }
@Override public void serialize(final Object value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException { final NodeAddress address = RemoteReference.getAddress((RemoteReference<?>) value); final Object actorId = RemoteReference.getId((RemoteReference<?>) value); jgen.writeString((address != null ? address.asUUID() : "") + "/" + actorId); }
@SuppressWarnings("unchecked") public static <T> T cast(Class<T> remoteInterface, Actor actor) { return (T) Proxy.newProxyInstance(DefaultDescriptorFactory.class.getClassLoader(), new Class[]{ remoteInterface }, (proxy, method, args) -> { // TODO: throw proper exceptions for the expected error scenarios (non task return), final int methodId = instance.dynamicReferenceFactory.getMethodId(method); return ActorRuntime.getRuntime() .invoke(RemoteReference.from(actor), method, method.isAnnotationPresent(OneWay.class), methodId, args); }); } }