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); }
@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 <R> Class<R> getInterfaceClass(final AbstractActor reference) { return from(reference)._interfaceClass(); }
@Override public Task<Void> clearState(final RemoteReference<?> reference, final Object state) { DB db = mongoClient.getDB(database); final DBCollection col = db.getCollection(RemoteReference.getInterfaceClass(reference).getSimpleName()); col.remove(new BasicDBObject("_id", String.valueOf(RemoteReference.getId(reference)))); return Task.done(); }
protected String getIdentity(final RemoteReference<?> reference) { return String.valueOf(RemoteReference.getId(reference)); }
@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); }); } }
/** * 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(); }
/** * 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(); }
@Override @SuppressWarnings("unchecked") public Task<Void> writeState(final RemoteReference<?> reference, final Object state) { DB db = mongoClient.getDB(database); final DBCollection col = db.getCollection(RemoteReference.getInterfaceClass(reference).getSimpleName()); JacksonDBCollection<Object, String> coll = JacksonDBCollection.wrap( col, (Class<Object>) state.getClass(), String.class, mapper); DBObject obj = coll.convertToDbObject(state); obj.put("_id", String.valueOf(RemoteReference.getId(reference))); col.save(obj); return Task.done(); }
@Override public boolean equals(final Object o) { RemoteReference<?> that; return (this == o) || ((o instanceof RemoteReference) && ((_interfaceId() == (that = (RemoteReference<?>) o)._interfaceId()) && ((!(address != null ? !address.equals(that.address) : that.address != null)) && ((!(id != null ? !id.equals(that.id) : that.id != null)))))); }
@Override public String toString() { if (address == null) { return id != null ? _interfaceClass().getName() + ":" + id : _interfaceClass().getName(); } return id != null ? _interfaceClass().getName() + ":" + id : _interfaceClass().getName() + ":" + address; }
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); }
@Override @SuppressWarnings("unchecked") public Task<Boolean> readState(final RemoteReference<?> reference, final Object state) { DB db = mongoClient.getDB(database); final DBCollection col = db.getCollection(RemoteReference.getInterfaceClass(reference).getSimpleName()); JacksonDBCollection<Object, String> coll = JacksonDBCollection.wrap( col, (Class<Object>) state.getClass(), String.class, mapper); DBObject obj = col.findOne(String.valueOf(RemoteReference.getId(reference))); if (obj != null) { try { obj.removeField("_id"); mapper.readerForUpdating(state).readValue(new BsonObjectTraversingParser( coll, obj, mapper)); return Task.fromValue(true); } catch (Exception e) { throw new UncheckedException("Error reading state of: " + reference, e); } } return Task.fromValue(false); }
@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); }
@Override public int hashCode() { int result = address != null ? address.hashCode() : 0; result = 31 * result + _interfaceId(); result = 31 * result + (id != null ? id.hashCode() : 0); return result; }
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); }
if (method == null) method = DefaultDescriptorFactory.get().getInvoker(RemoteReference.getInterfaceClass(toReference)).getMethod(invocation.getMethodId()); String to = wrap(RemoteReference.getInterfaceClass(toReference).getSimpleName() + ":" + RemoteReference.getId(toReference), 32, "\\n", false);
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); }
if (method == null) method = DefaultDescriptorFactory.get().getInvoker(RemoteReference.getInterfaceClass(toReference)).getMethod(invocation.getMethodId()); String to = wrap(RemoteReference.getInterfaceClass(toReference).getSimpleName() + ":" + RemoteReference.getId(toReference), 32, "\\n", false);