Java 类akka.actor.TypedProps 实例源码

项目:karajan    文件:OrchestrationSystemTest.java   
@BeforeClass
public static void setup() {
    handler.addExceptionElement(e1);
    handler.addExceptionElement(e2);
    s2=new ActorStep("step2",5, null,impl2,handler);
    s1=new ActorStep("step1",5, s2,impl1,handler);
    s1.setWorkRef(0);model.add(s1);
    s2.setWorkRef(1);model.add(s2);
    for(int i=0;i<10;i++){
        data.add(i+1);
    }
    orchestrator =
            TypedActor.get(_system).typedActorOf(
            new TypedProps<OrchestratorImpl>(Orchestrator.class,
            new Creator<OrchestratorImpl>() {
            /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

            public OrchestratorImpl create() { return new OrchestratorImpl(model,batchproducer); }
            }),
            "orchestrator");    
}
项目:trial    文件:CalculatorActorSytem.java   
public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("TypedActorsExample");

    CalculatorInt calculator1 = TypedActor.get(_system).typedActorOf(
            new TypedProps<Calculator>(CalculatorInt.class,
                    Calculator.class));

    CalculatorInt calculator2 = TypedActor.get(_system).typedActorOf(
            new TypedProps<Calculator>(CalculatorInt.class,
                    Calculator.class));

    // Create a router with Typed Actors
    ActorRef actor1 = TypedActor.get(_system).getActorRefFor(calculator1);
    ActorRef actor2 = TypedActor.get(_system).getActorRefFor(calculator2);

    Iterable<ActorRef> routees = Arrays.asList(new ActorRef[] { actor1,
            actor2 });
    ActorRef router = _system.actorOf(new Props()
            .withRouter(BroadcastRouter.create(routees)));

    router.tell("Hello there");

    _system.shutdown();

}
项目:aorra    文件:GuiceInjectionPlugin.java   
private <T> T typedActor(final Injector injector, 
    final Class<T> iface, final Class <? extends T> impl) {
  return TypedActor.get(Akka.system()).typedActorOf(
      new TypedProps<T>(iface, new Creator<T>() {
        @Override
        public T create() {
          return injector.getInstance(impl);
        }
      }));
}
项目:Megapode    文件:HttpServer.java   
public HttpHandler(final ActorSystem system, final ActorRef coordinator) {
    super();
    this.coordinator = coordinator;
    this.system = system;

    requester = TypedActor.get(system).typedActorOf(
            new TypedProps<RequestHandlerActor>(
                    RequestHandlerActor.class,
                    new Creator<RequestHandlerActor>() {
                        public RequestHandlerActor create() {
                            return new RequestHandlerActor(coordinator);
                        }
                    }), "entrypoint");
}
项目:trial    文件:CalculatorActorSytem.java   
public static void main(String[] args) throws Exception {

        ActorSystem _system = ActorSystem.create("TypedActorsExample",
                ConfigFactory.load().getConfig("TypedActorExample"));

        CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
                new TypedProps<SupervisorActor>(CalculatorInt.class,
                        SupervisorActor.class),"supervisorActor");

        // Get access to the ActorRef
        ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
        // call actor with a message
        calActor.tell("Hi there",calActor);

        //wait for child actor to get restarted
        Thread.sleep(500);

        // Invoke the method and wait for result
        Timeout timeout = new Timeout(Duration.parse("5 seconds"));
        Future<Object> future = Patterns.ask(calActor, Integer.valueOf(10), timeout);
        Integer result = (Integer) Await.result(future, timeout.duration());

        System.out.println("Result from child actor->" + result);

        //wait before shutting down the system
        Thread.sleep(500);

        _system.shutdown();

    }
项目:trial    文件:CalculatorActorSytem.java   
public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("TypedActorsExample");

    Timeout timeout = new Timeout(Duration.parse("5 seconds"));

    CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
            new TypedProps<Calculator>(CalculatorInt.class,
                    Calculator.class));

    // calling a fire and forget method
    calculator.incrementCount();

    // Invoke the method and wait for result
    Future<Integer> future = calculator.add(Integer.valueOf(14),
            Integer.valueOf(6));
    Integer result = Await.result(future, timeout.duration());

    System.out.println("Result is " + result);

    Option<Integer> counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());

    counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());

    // Get access to the ActorRef
    ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
    // call actor with a message
    calActor.tell("Hi there");

    _system.shutdown();

}
项目:trial    文件:CalculatorActorSytem.java   
public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("TypedActorsExample",
            ConfigFactory.load().getConfig("TypedActorExample"));

    Timeout timeout = new Timeout(Duration.parse("5 seconds"));

    CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
            new TypedProps<Calculator>(CalculatorInt.class,
                    Calculator.class).withDispatcher("defaultDispatcher"));

    // calling a fire and forget method
    calculator.incrementCount();

    // Invoke the method and wait for result
    Future<Integer> future = calculator.add(Integer.valueOf(14),
            Integer.valueOf(6));
    Integer result = Await.result(future, timeout.duration());

    System.out.println("Result is " + result);

    Option<Integer> counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());

    counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());

    // Get access to the ActorRef
    ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
    // call actor with a message
    calActor.tell("Hi there");

    _system.shutdown();

}
项目:wicket-akka    文件:AkkaWebApplication.java   
@Override
public final <T> T typedActorOf(TypedProps<T> props, String name) {
    return akka.typedActorOf(props, name);
}
项目:wicket-akka    文件:AkkaWebApplication.java   
@Override
public final <T> T typedActorOf(TypedProps<T> props) {
    return akka.typedActorOf(props);
}
项目:wicket-akka    文件:AkkaWebApplication.java   
@Override
public final <T> T typedActorOf(TypedProps<T> props, ActorRef actorRef) {
    return akka.typedActorOf(props, actorRef);
}
项目:wicket-akka    文件:TypedActorFactory.java   
public TypedActorFactory(Akka akka, TypedProps<T> props) {
    this(akka, props, null);
}
项目:wicket-akka    文件:TypedActorFactory.java   
public TypedActorFactory(Akka akka, TypedProps<T> props, String name) {
    this.akka = akka;
    this.props = props;
    this.name = name;
}
项目:wicket-akka    文件:TypedPropsFactory.java   
public TypedProps<T> create() {
    return TProps.create(interfaceClass, implementationClass);
}
项目:wicket-akka    文件:AkkaTest.java   
public static TypedProps<Impl> props() {
    return Holder.props;
}
项目:karajan    文件:OrchestratorTest.java   
@SuppressWarnings("serial")
public static void main(String[] args) {

    // instanciation of the actor model
    ActorSystem _system = ActorSystem.create("Karajan");
    // Data to be processed
    final List<Integer> data=new ArrayList<Integer>();
    for(int i=0;i<10;i++){
        data.add(i+1);
    }
    // Some implementations
    String impl1="com.wordline.awltech.karajan.orchestrator.masterslavepullpatterntest.Implementation1";
    String impl2="com.wordline.awltech.karajan.orchestrator.masterslavepullpatterntest.Implementation2"; 
    // Somme Error Handling
    ExceptionElement e1=new ExceptionElement("ProcessorException", ErrorStrategy.ONE, Action.SKIP, 5);
    ExceptionElement e2=new ExceptionElement("ArithmeticException", ErrorStrategy.ONE, Action.SKIP, 5);
    ErrorHandling handler=new  ErrorHandling();
    handler.addExceptionElement(e1);
    handler.addExceptionElement(e2);
    // instanciation of some steps
    ActorStep s2=new ActorStep("step2",5, null,impl2,handler);
    ActorStep s1=new ActorStep("step1",5, s2,impl1,handler);
    //Model
    final List<ActorStep> model=new ArrayList<ActorStep>();
    s1.setWorkRef(0);model.add(s1);
    s2.setWorkRef(1);model.add(s2);
      final ActorRef batchproducer =_system.actorOf(Props.create(BatchProducer.class,data.iterator(),5));
    // instanciation of the orchestration
            Orchestrator orchestrator =
                    TypedActor.get(_system).typedActorOf(
                    new TypedProps<OrchestratorImpl>(Orchestrator.class,
                    new Creator<OrchestratorImpl>() {
                    public OrchestratorImpl create() { return new OrchestratorImpl(model,batchproducer); }
                    }),
                    "orchestrator");    
    while(orchestrator.getBatchStatus()!=BatchStatus.COMPLETED){
        System.out.println(orchestrator.getBatchStatus());
    }
    if(orchestrator.getBatchStatus()==BatchStatus.COMPLETED){
        System.out.println("STATUS AT THE END: "+orchestrator.getBatchStatus());
        System.out.println("PROCESSED: "+orchestrator.getStepMetrics("step1").PROCESSED);
        System.out.println("RECEIVED: "+orchestrator.getStepMetrics("step1").RECEIVED);
        _system.shutdown();
    }







}
项目:wicket-akka    文件:IAkkaApplication.java   
/**
 * creates a new typed actor
 *
 * @param props the {@link akka.actor.Props} to use to create the actor
 * @param name the name of the actor
 * @param <T> type of the typed actor
 * @return a new typed actor instance
 */
<T> T typedActorOf(TypedProps<T> props, String name);
项目:wicket-akka    文件:IAkkaApplication.java   
/**
 * creates a new typed actor that is baked by a normal actor. This is usable if you want to communicate remotely
 * with TypedActors on other machines
 *
 * @param props the {@link akka.actor.Props} to use to create the actor
 * @param actorRef the actor that implements the typed actor
 * @param <T> type of the typed actor
 * @return a new typed actor instance
 */
<T> T typedActorOf(TypedProps<T> props, ActorRef actorRef);
项目:wicket-akka    文件:IAkkaApplication.java   
/**
 * creates a new typed actor
 *
 * @param props the {@link akka.actor.Props} to use to create the actor
 * @param <T> type of the typed actor
 * @return a new typed actor instance
 */
<T> T typedActorOf(TypedProps<T> props);
项目:wicket-akka    文件:TProps.java   
/**
 * creates a new {@link akka.actor.TypedProps} instance.
 *
 * @param interfaceClass the interface class
 * @param implClass the implementation class
 * @param <T> the type of implementation class
 * @return new implementation instance
 */
public static <T> TypedProps<T> create(Class<? super T> interfaceClass, Class<T> implClass) {
    return new TypedProps<T>(interfaceClass, implClass);
}
项目:wicket-akka    文件:Akka.java   
/**
 * Creates a TypedActor that intercepts the calls and forwards them as {@link akka.actor.TypedActor.MethodCall}
 * to the provided ActorRef.
 */
public <T> T typedActorOf(TypedProps<T> props, String name) {
    return typedActorExtension().typedActorOf(props, name);
}
项目:wicket-akka    文件:Akka.java   
/**
 * Creates a TypedActor that intercepts the calls and forwards them as {@link akka.actor.TypedActor.MethodCall}
 * to the provided ActorRef.
 */
public <T> T typedActorOf(TypedProps<T> props) {
    return typedActorExtension().typedActorOf(props);
}
项目:wicket-akka    文件:Akka.java   
/**
 * Creates a TypedActor that intercepts the calls and forwards them as {@link akka.actor.TypedActor.MethodCall}
 * to the provided ActorRef.
 */
public <T> T typedActorOf(TypedProps<T> props, ActorRef actorRef) {
    return typedActorExtension().typedActorOf(props, actorRef);
}