dynamicReferenceFactory = new ActorFactoryGenerator(); factory = dynamicReferenceFactory.getFactoryFor(iClass);
@Override public ObjectInvoker<?> getInvoker(Class clazz) { final ClassDescriptor descriptor = getDescriptor(clazz); if (descriptor == null) { return null; } if (descriptor.invoker == null) { descriptor.invoker = dynamicReferenceFactory.getInvokerFor(clazz); } return descriptor.invoker; }
@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); }); } }
ActorFactoryGenerator afg = new ActorFactoryGenerator(); Stream.of(getClass().getClasses()) .forEach(c -> { if (Actor.class.isAssignableFrom(c) && c.isInterface()) afg.getFactoryFor(c); stage.getHosting().canActivate(c.getName()).join(); afg.getInvokerFor(c);
@SuppressWarnings("unchecked") private ClassDescriptor getDescriptor(final Class<?> aInterface) { ClassDescriptor descriptor = descriptorMapByInterface.get(aInterface); if (descriptor == null) { if (aInterface == Actor.class || aInterface == ActorObserver.class) { return null; } descriptor = new ClassDescriptor(); descriptor.isObserver = ActorObserver.class.isAssignableFrom(aInterface); if (aInterface.isInterface()) { descriptor.factory = dynamicReferenceFactory.getFactoryFor(aInterface); descriptor.invoker = (ObjectInvoker<Object>) descriptor.factory.getInvoker(); } ClassDescriptor concurrentInterfaceDescriptor = descriptorMapByInterface.putIfAbsent(aInterface, descriptor); if (concurrentInterfaceDescriptor != null) { descriptorMapByInterfaceId.put(DefaultClassDictionary.get().getClassId(aInterface), concurrentInterfaceDescriptor); return concurrentInterfaceDescriptor; } descriptorMapByInterfaceId.put(DefaultClassDictionary.get().getClassId(aInterface), descriptor); } return descriptor; }
private <T> Class<?> makeInvokerClass(final Class<T> actorClass, final String invokerFullName) throws NotFoundException, CannotCompileException Class clazz = lookup(invokerFullName); if (clazz != null) clazz = lookup(invokerFullName); if (clazz != null) final int methodId = computeMethodId(methodName, parameterTypes); unwrapParams(invokerBody, parameterTypes, "params"); invokerBody.append("); ");
@SuppressWarnings("unchecked") private <T> Class<T> makeReferenceClass(final Class<T> aInterface, final String interfaceFullName, final int interfaceId, final String referenceFullName) throws NotFoundException, CannotCompileException Class clazz = lookup(referenceFullName); if (clazz != null) clazz = lookup(referenceFullName); if (clazz != null) final CtClass[] parameterTypes = m.getParameterTypes(); final int methodId = computeMethodId(methodName, parameterTypes);
protected Class<?> getStateClass() { final Class<? extends AbstractActor> aClass = getClass(); return ActorFactoryGenerator.makeStateClass(aClass); }
public ObjectInvoker<Object> getInvokerFor(final Class<?> concreteClass) { try { final Class<?> aClass = makeInvokerClass(concreteClass, concreteClass.getName() + "$ObjectInvoker"); return (ObjectInvoker<Object>) aClass.newInstance(); } catch (Exception e) { throw new UncheckedException(e); } }
@SuppressWarnings("unchecked") public <T> ReferenceFactory<T> getFactoryFor(final Class<T> aInterface) { final String interfaceFullName = aInterface.getName().replace('$', '.'); final int interfaceId = DefaultClassDictionary.get().getClassId(aInterface); final String referenceFullName = aInterface.getName() + "$Reference"; try { final Class<T> referenceClass = makeReferenceClass(aInterface, interfaceFullName, interfaceId, referenceFullName); final GenericActorFactory<T> dyn = new GenericActorFactory<>(); dyn.interfaceId = interfaceId; dyn.interfaceClass = aInterface; dyn.referenceConstructor = referenceClass.getConstructor(String.class); return dyn; } catch (final Exception e) { throw new UncheckedException(e); } }
ActorFactoryGenerator afg = new ActorFactoryGenerator(); Stream.of(getClass().getClasses()) .forEach(c -> { if (Actor.class.isAssignableFrom(c) && c.isInterface()) afg.getFactoryFor(c); stage.getHosting().canActivate(c.getName()).join(); afg.getInvokerFor(c);
public ObjectInvoker<?> getInvoker(final int interfaceId) { final ClassDescriptor descriptor = getDescriptor(interfaceId); if (descriptor == null) { return getInvoker(DefaultClassDictionary.get().getClassById(interfaceId)); } if (descriptor.invoker == null) { descriptor.invoker = dynamicReferenceFactory.getInvokerFor(descriptor.factory.getInterface()); } return descriptor.invoker; }