SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Jactor Code Samples
●   Slides: http://sourceforge.net/projects/jactor/files/Code%20Samples%2012-JUN-2012.pdf/download
●   Code:
    https://github.com/anirbanbhattacharjee/jactor-in-action
JActor
●   Getting Started
●   Basic Code Samples
●   State Machines
Getting Started
●   The JActor jar file
●   Create a test environment
The JActor jar file
●   Download Jactor-3.1.0.zip from
    https://sourceforge.net/projects/jactor/files/
●   Extract jactor-3.1.0.jar from the zip file and copy
    it to a new directory, GettingStarted.
●   (The JActor version will change—current
    version is 3.1.0.)
Create a Test Environment
●   Create a j.bat file in the GettingStarted
    directory:
       del *.class
       call javac -classpath jactor-3.1.0.jar *.java
       call java -classpath .;jactor-3.1.0.jar GettingStarted

●   The j.bat file can be used to run a test.
Basic Code Samples
●   Hello world!
●   Actor <==> Actor
●   RP Games
●   Parallel Programming
●   Dependency Injection
●   Exception Handling
●   Loops
Hello world!
●   GettingStarted.java (main)
●   Test.java (actor)
●   Start.java (request)
GettingStarted.java
                  (main)
import org.agilewiki.jactor.*;

public class GettingStarted {
    public static void main(String[] args) throws Exception {
        MailboxFactory mailboxFactory =
            JAMailboxFactory.newMailboxFactory(10);
        Mailbox mailbox = mailboxFactory.createMailbox();
        JAFuture future = new JAFuture();
        Test test = new Test();
        test.initialize(mailbox);
        Start.req.send(future, test);
        mailboxFactory.close();
    }
}
Test.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(RP rp) throws Exception {
        System.out.println("Hello world!");
        rp.processResponse(null);
    }
}
Start.java
                     (request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Start extends Request<Object, Test> {

    public static final Start req = new Start();

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        Test a = (Test) targetActor;
        a.start(rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof Test;
    }
}
Output
Hello world!
GettingStarted>
Actor <==> Actor
●   Test.java (actor)
●   Greeter.java (actor)
●   Greet.java (request)
Test.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(final RP rp) throws Exception {
        Greeter greeter = new Greeter();
        greeter.initialize(getMailbox());
        Greet.req.send(this, greeter, new RP<String>() {
            public void processResponse(String greeting)
                    throws Exception {
                System.out.println(greeting);
                rp.processResponse(null);
            }
        });
    }
}
Greeter.java
                    (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Greeter extends JLPCActor {
    public void greet(RP rp) throws Exception {
        rp.processResponse("Hello world!");
    }
}
Greet.java
                    (request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Greet extends Request<String, Greeter> {

    public static final Greet req = new Greet();

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        Greeter a = (Greeter) targetActor;
        a.greet(rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof Greeter;
    }
}
Output
Hello world!
GettingStarted>
RP Games
●   Test.java (actor)
●   Greeter.java (actor)
●   Trigger.java (request)
Test.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(final RP rp) throws Exception {
        Greeter greeter = new Greeter();
        greeter.initialize(getMailbox());
        Greet.req.send(this, greeter, new RP<String>() {
            public void processResponse(String greeting)
                    throws Exception {
                System.out.println(greeting);
                rp.processResponse(null);
            }
        });
        System.out.println("trigger...");
        Trigger.req.sendEvent(this, greeter);
    }
}
Greeter.java
                    (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Greeter extends JLPCActor {
    private RP rp;

    public void greet(RP rp) throws Exception {
        this.rp = rp;
    }

    public void trigger(RP rp) throws Exception {
        rp.processResponse(null);
        this.rp.processResponse("Hello world!");
    }
}
Trigger.java
                    (request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Trigger extends Request<Object, Greeter> {

    public static final Trigger req = new Trigger();

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        Greeter a = (Greeter) targetActor;
        a.trigger(rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof Greeter;
    }
}
Output
Trigger...
Hello world!
GettingStarted>
Parallel Programming
●   Test.java (actor)
●   Timer.java (actor)
●   Delay.java (request)
Test.java
                         (actor)
public class Test extends JLPCActor {
    public void start(final RP rp) throws Exception {
        Timer timer1 = new Timer();
        timer1.initialize(
            getMailboxFactory().createAsynchronousMailbox());
        Timer timer2 = new Timer();
        timer2.initialize(
            getMailboxFactory().createAsynchronousMailbox());
        final long t0 = System.currentTimeMillis();
        RP prp = new RP() {
            boolean pending = true;
            public void processResponse(Object obj) throws Exception {
                if (pending) pending = false;
                else {
                    System.out.println(System.currentTimeMillis()-t0);
                    rp.processResponse(null);
                }
            }
        };
        (new Delay(1000)).send(this, timer1, prp);
        (new Delay(1000)).send(this, timer2, prp);
    }
}
Timer.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Timer extends JLPCActor {
    public void delay(int ms, RP rp) throws Exception {
        Thread.sleep(ms);
        rp.processResponse(null);
    }
}
Delay.java
                    (request)
public class Delay extends Request<Object, Timer> {

    public final int ms;

    public Delay(int ms) {
        this.ms = ms;
    }

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        Timer a = (Timer) targetActor;
        a.delay(ms, rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof Timer;
    }
}
Output
1003
GettingStarted>
Dependency Injection
●   Test.java (actor)
●   Greeter.java (actor)
●   Printer.java(actor)
●   Print.java (request)
Test.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(final RP rp) throws Exception {
        Printer printer = new Printer();
        printer.initialize(getMailbox());
        final Greeter greeter = new Greeter();
        greeter.initialize(getMailbox(), printer);
        (new Print("Greeting:")).
                send(this, greeter, new RP() {
            public void processResponse(Object rsp)
                    throws Exception {
                Greet.req.send(Test.this, greeter, rp);
            }
        });
    }
}
Greeter.java
                    (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Greeter extends JLPCActor {
    public void greet(RP rp) throws Exception {
        (new Print("Hello world!")).send(this, this, rp);
    }
}
Printer.java
                     (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Printer extends JLPCActor {
    public void print(String value, RP rp) throws Exception {
        System.out.println(value);
        rp.processResponse(null);
    }
}
Print.java
                     (request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Print extends Request<Object, Printer> {
    public final String value;

    public Print(String value) {
        this.value = value;
    }

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        Printer a = (Printer) targetActor;
        a.processRequest(value, rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof Printer;
    }
}
Output
Greeting:
Hello world!
GettingStarted>
Exception Handling
●   Test.java (actor)
●   ThrowsException.java (actor)
●   ThrowException.java (request)
Test.java
                         (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(final RP rp) throws Exception {
        ThrowsException throwsException = new ThrowsException();
        throwsException.initialize(getMailbox());
        setExceptionHandler(new ExceptionHandler() {
            public void process(Exception exception)
                    throws Exception {
                System.out.println(exception.getMessage());
                rp.processResponse(null);
            }
        });
        ThrowException.req.send(this, throwsException, new RP() {
            public void processResponse(Object response)
                    throws Exception {
                System.out.println("No exception");
                rp.processResponse(null);
            }
        });
    }
}
ThrowsException
                  (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class ThrowsException extends JLPCActor {
    public void throwException(RP rp) throws Exception {
        throw new Exception("Boo!");
    }
}
ThrowException
                  (request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class ThrowException
        extends Request<Object, ThrowsException> {

    public static final ThrowException req =
            new ThrowException();

    public void processRequest(JLPCActor targetActor, RP rp)
            throws Exception {
        ThrowsException a = (ThrowsException) targetActor;
        a.throwException(rp);
    }

    public boolean isTargetType(Actor targetActor) {
        return targetActor instanceof ThrowsException;
    }
}
Output
Boo!
GettingStarted>
Loops
●   Test.java (actor)
Test.java
                      (actor)
public class Test extends JLPCActor {
    public void start(RP rp) throws Exception {
        Printer printer = new Printer();
        printer.initialize(getMailbox());
        final int max = 5;
        (new JAIterator() {
            int i = 0;

            protected void process(RP irp) throws Exception {
                if (i == max) irp.processResponse("done");
                else {
                    i += 1;
                    (new Print(""+i)).
                        send(Test.this, printer, irp);
                }
            }
        }).iterate(rp);
    }
}
Output
1
2
3
4
5
GettingStarted>
State Machines
●   A Sequence of Requests
●   Looping
A Sequence of Requests
●   Test.java (actor)
Test.java
                      (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;

public class Test extends JLPCActor {
    public void start(RP rp) throws Exception {
        Printer printer = new Printer();
        printer.initialize(getMailbox());
        SMBuilder smb = new SMBuilder();
        smb._send(printer, new Print("a"));
        smb._send(printer, new Print("b"));
        smb._send(printer, new Print("c"));
        smb.call(rp);
    }
}
Output
a
b
c
GettingStarted>
Looping
●   Test.java (actor)
Test.java
                             (actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;
import org.agilewiki.jactor.stateMachine.*;

public class Test extends JLPCActor {
    int counter;

    public void start(RP rp) throws Exception {
        Printer printer = new Printer();
        printer.initialize(getMailbox());
        SMBuilder smb = new SMBuilder();
        counter = 1;
        smb._label("loop");
        smb._send(printer, new ObjectFunc() {
            public Object get(StateMachine sm) {
                return new Print(""+counter);
            }
        });
        smb._if(new BooleanFunc() {
            public boolean get(StateMachine sm) {
                counter += 1;
                return counter < 6;
            }
        }, "loop");
        smb.call(rp);
    }
}
Output
1
2
3
4
5
GettingStarted>

Weitere ähnliche Inhalte

Was ist angesagt?

Testing Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaTesting Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaFabio Collini
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydneyjulien.ponge
 
Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloadedcbeyls
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxDavid Rodenas
 
Loaders (and why we should use them)
Loaders (and why we should use them)Loaders (and why we should use them)
Loaders (and why we should use them)Michael Pustovit
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKFabio Collini
 
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta IndonesiaAndroid architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta IndonesiaPratama Nur Wijaya
 
The Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesThe Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesHaim Yadid
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...Victoria Schiffer
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaJose María Arranz
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for ProgrammersDavid Rodenas
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 

Was ist angesagt? (20)

Introduzione al TDD
Introduzione al TDDIntroduzione al TDD
Introduzione al TDD
 
Testing Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaTesting Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJava
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
 
Android Loaders : Reloaded
Android Loaders : ReloadedAndroid Loaders : Reloaded
Android Loaders : Reloaded
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
Java Quiz Questions
Java Quiz QuestionsJava Quiz Questions
Java Quiz Questions
 
Loaders (and why we should use them)
Loaders (and why we should use them)Loaders (and why we should use them)
Loaders (and why we should use them)
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
 
Android architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta IndonesiaAndroid architecture component - FbCircleDev Yogyakarta Indonesia
Android architecture component - FbCircleDev Yogyakarta Indonesia
 
The Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFuturesThe Future of Futures - A Talk About Java 8 CompletableFutures
The Future of Futures - A Talk About Java 8 CompletableFutures
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...
Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July ...
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
RelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with JavaRelProxy, Easy Class Reload and Scripting with Java
RelProxy, Easy Class Reload and Scripting with Java
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
ReactJS for Programmers
ReactJS for ProgrammersReactJS for Programmers
ReactJS for Programmers
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 

Ähnlich wie Code Samples

201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programingwahyuseptiansyah
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfADITIEYEWEAR
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниStfalcon Meetups
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsPROIDEA
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldtcurdt
 
05 pig user defined functions (udfs)
05 pig user defined functions (udfs)05 pig user defined functions (udfs)
05 pig user defined functions (udfs)Subhas Kumar Ghosh
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8Dhaval Dalal
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesGanesh Samarthyam
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Anton Arhipov
 

Ähnlich wie Code Samples (20)

Server1
Server1Server1
Server1
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
Testing in android
Testing in androidTesting in android
Testing in android
 
import javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdfimport javaxswing import javaawtevent import javai.pdf
import javaxswing import javaawtevent import javai.pdf
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
RxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камниRxJava и Android. Плюсы, минусы, подводные камни
RxJava и Android. Плюсы, минусы, подводные камни
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
 
No dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real worldNo dark magic - Byte code engineering in the real world
No dark magic - Byte code engineering in the real world
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
05 pig user defined functions (udfs)
05 pig user defined functions (udfs)05 pig user defined functions (udfs)
05 pig user defined functions (udfs)
 
Akka
AkkaAkka
Akka
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Java 8
Java 8Java 8
Java 8
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012
 

Kürzlich hochgeladen

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Code Samples

  • 1. Jactor Code Samples ● Slides: http://sourceforge.net/projects/jactor/files/Code%20Samples%2012-JUN-2012.pdf/download ● Code: https://github.com/anirbanbhattacharjee/jactor-in-action
  • 2. JActor ● Getting Started ● Basic Code Samples ● State Machines
  • 3. Getting Started ● The JActor jar file ● Create a test environment
  • 4. The JActor jar file ● Download Jactor-3.1.0.zip from https://sourceforge.net/projects/jactor/files/ ● Extract jactor-3.1.0.jar from the zip file and copy it to a new directory, GettingStarted. ● (The JActor version will change—current version is 3.1.0.)
  • 5. Create a Test Environment ● Create a j.bat file in the GettingStarted directory: del *.class call javac -classpath jactor-3.1.0.jar *.java call java -classpath .;jactor-3.1.0.jar GettingStarted ● The j.bat file can be used to run a test.
  • 6. Basic Code Samples ● Hello world! ● Actor <==> Actor ● RP Games ● Parallel Programming ● Dependency Injection ● Exception Handling ● Loops
  • 7. Hello world! ● GettingStarted.java (main) ● Test.java (actor) ● Start.java (request)
  • 8. GettingStarted.java (main) import org.agilewiki.jactor.*; public class GettingStarted { public static void main(String[] args) throws Exception { MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(10); Mailbox mailbox = mailboxFactory.createMailbox(); JAFuture future = new JAFuture(); Test test = new Test(); test.initialize(mailbox); Start.req.send(future, test); mailboxFactory.close(); } }
  • 9. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(RP rp) throws Exception { System.out.println("Hello world!"); rp.processResponse(null); } }
  • 10. Start.java (request) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Start extends Request<Object, Test> { public static final Start req = new Start(); public void processRequest(JLPCActor targetActor, RP rp) throws Exception { Test a = (Test) targetActor; a.start(rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof Test; } }
  • 12. Actor <==> Actor ● Test.java (actor) ● Greeter.java (actor) ● Greet.java (request)
  • 13. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(final RP rp) throws Exception { Greeter greeter = new Greeter(); greeter.initialize(getMailbox()); Greet.req.send(this, greeter, new RP<String>() { public void processResponse(String greeting) throws Exception { System.out.println(greeting); rp.processResponse(null); } }); } }
  • 14. Greeter.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Greeter extends JLPCActor { public void greet(RP rp) throws Exception { rp.processResponse("Hello world!"); } }
  • 15. Greet.java (request) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Greet extends Request<String, Greeter> { public static final Greet req = new Greet(); public void processRequest(JLPCActor targetActor, RP rp) throws Exception { Greeter a = (Greeter) targetActor; a.greet(rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof Greeter; } }
  • 17. RP Games ● Test.java (actor) ● Greeter.java (actor) ● Trigger.java (request)
  • 18. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(final RP rp) throws Exception { Greeter greeter = new Greeter(); greeter.initialize(getMailbox()); Greet.req.send(this, greeter, new RP<String>() { public void processResponse(String greeting) throws Exception { System.out.println(greeting); rp.processResponse(null); } }); System.out.println("trigger..."); Trigger.req.sendEvent(this, greeter); } }
  • 19. Greeter.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Greeter extends JLPCActor { private RP rp; public void greet(RP rp) throws Exception { this.rp = rp; } public void trigger(RP rp) throws Exception { rp.processResponse(null); this.rp.processResponse("Hello world!"); } }
  • 20. Trigger.java (request) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Trigger extends Request<Object, Greeter> { public static final Trigger req = new Trigger(); public void processRequest(JLPCActor targetActor, RP rp) throws Exception { Greeter a = (Greeter) targetActor; a.trigger(rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof Greeter; } }
  • 22. Parallel Programming ● Test.java (actor) ● Timer.java (actor) ● Delay.java (request)
  • 23. Test.java (actor) public class Test extends JLPCActor { public void start(final RP rp) throws Exception { Timer timer1 = new Timer(); timer1.initialize( getMailboxFactory().createAsynchronousMailbox()); Timer timer2 = new Timer(); timer2.initialize( getMailboxFactory().createAsynchronousMailbox()); final long t0 = System.currentTimeMillis(); RP prp = new RP() { boolean pending = true; public void processResponse(Object obj) throws Exception { if (pending) pending = false; else { System.out.println(System.currentTimeMillis()-t0); rp.processResponse(null); } } }; (new Delay(1000)).send(this, timer1, prp); (new Delay(1000)).send(this, timer2, prp); } }
  • 24. Timer.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Timer extends JLPCActor { public void delay(int ms, RP rp) throws Exception { Thread.sleep(ms); rp.processResponse(null); } }
  • 25. Delay.java (request) public class Delay extends Request<Object, Timer> { public final int ms; public Delay(int ms) { this.ms = ms; } public void processRequest(JLPCActor targetActor, RP rp) throws Exception { Timer a = (Timer) targetActor; a.delay(ms, rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof Timer; } }
  • 27. Dependency Injection ● Test.java (actor) ● Greeter.java (actor) ● Printer.java(actor) ● Print.java (request)
  • 28. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(final RP rp) throws Exception { Printer printer = new Printer(); printer.initialize(getMailbox()); final Greeter greeter = new Greeter(); greeter.initialize(getMailbox(), printer); (new Print("Greeting:")). send(this, greeter, new RP() { public void processResponse(Object rsp) throws Exception { Greet.req.send(Test.this, greeter, rp); } }); } }
  • 29. Greeter.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Greeter extends JLPCActor { public void greet(RP rp) throws Exception { (new Print("Hello world!")).send(this, this, rp); } }
  • 30. Printer.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Printer extends JLPCActor { public void print(String value, RP rp) throws Exception { System.out.println(value); rp.processResponse(null); } }
  • 31. Print.java (request) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Print extends Request<Object, Printer> { public final String value; public Print(String value) { this.value = value; } public void processRequest(JLPCActor targetActor, RP rp) throws Exception { Printer a = (Printer) targetActor; a.processRequest(value, rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof Printer; } }
  • 33. Exception Handling ● Test.java (actor) ● ThrowsException.java (actor) ● ThrowException.java (request)
  • 34. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(final RP rp) throws Exception { ThrowsException throwsException = new ThrowsException(); throwsException.initialize(getMailbox()); setExceptionHandler(new ExceptionHandler() { public void process(Exception exception) throws Exception { System.out.println(exception.getMessage()); rp.processResponse(null); } }); ThrowException.req.send(this, throwsException, new RP() { public void processResponse(Object response) throws Exception { System.out.println("No exception"); rp.processResponse(null); } }); } }
  • 35. ThrowsException (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class ThrowsException extends JLPCActor { public void throwException(RP rp) throws Exception { throw new Exception("Boo!"); } }
  • 36. ThrowException (request) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class ThrowException extends Request<Object, ThrowsException> { public static final ThrowException req = new ThrowException(); public void processRequest(JLPCActor targetActor, RP rp) throws Exception { ThrowsException a = (ThrowsException) targetActor; a.throwException(rp); } public boolean isTargetType(Actor targetActor) { return targetActor instanceof ThrowsException; } }
  • 38. Loops ● Test.java (actor)
  • 39. Test.java (actor) public class Test extends JLPCActor { public void start(RP rp) throws Exception { Printer printer = new Printer(); printer.initialize(getMailbox()); final int max = 5; (new JAIterator() { int i = 0; protected void process(RP irp) throws Exception { if (i == max) irp.processResponse("done"); else { i += 1; (new Print(""+i)). send(Test.this, printer, irp); } } }).iterate(rp); } }
  • 41. State Machines ● A Sequence of Requests ● Looping
  • 42. A Sequence of Requests ● Test.java (actor)
  • 43. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; public class Test extends JLPCActor { public void start(RP rp) throws Exception { Printer printer = new Printer(); printer.initialize(getMailbox()); SMBuilder smb = new SMBuilder(); smb._send(printer, new Print("a")); smb._send(printer, new Print("b")); smb._send(printer, new Print("c")); smb.call(rp); } }
  • 45. Looping ● Test.java (actor)
  • 46. Test.java (actor) import org.agilewiki.jactor.*; import org.agilewiki.jactor.lpc.*; import org.agilewiki.jactor.stateMachine.*; public class Test extends JLPCActor { int counter; public void start(RP rp) throws Exception { Printer printer = new Printer(); printer.initialize(getMailbox()); SMBuilder smb = new SMBuilder(); counter = 1; smb._label("loop"); smb._send(printer, new ObjectFunc() { public Object get(StateMachine sm) { return new Print(""+counter); } }); smb._if(new BooleanFunc() { public boolean get(StateMachine sm) { counter += 1; return counter < 6; } }, "loop"); smb.call(rp); } }