-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RoryMalcolm/multi_party_session_types
Multi party session types
- Loading branch information
Showing
30 changed files
with
652 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/dynosesh/example/multiparty/bookstore/BookStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.dynosesh.example.multiparty.bookstore; | ||
|
||
import com.dynosesh.Sendable; | ||
import com.dynosesh.example.multiparty.bookstore.types.Okay; | ||
import com.dynosesh.example.multiparty.bookstore.types.SendableDateTime; | ||
import com.dynosesh.example.multiparty.bookstore.types.SendableInteger; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.net.Socket; | ||
import java.util.Date; | ||
|
||
public class BookStore implements Runnable { | ||
|
||
private int port; | ||
|
||
public BookStore(int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
Socket socket = new Socket("localhost", port); | ||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); | ||
objectOutputStream.flush(); | ||
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); | ||
streamsInitialised(objectOutputStream, objectInputStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (ClassNotFoundException e) { | ||
System.out.println("Protocol was violated on the BookStore!"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void streamsInitialised(ObjectOutputStream objectOutputStream, | ||
ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { | ||
Sendable inputTitle = (Sendable) objectInputStream.readObject(); | ||
System.out.println("BookStore: received " + inputTitle.getPayload()); | ||
objectOutputStream.writeObject(new SendableInteger(10, "1")); | ||
objectOutputStream.writeObject(new SendableInteger(10, "2")); | ||
objectOutputStream.writeObject(new Okay(true, "1")); | ||
Sendable inputOkay = (Sendable) objectInputStream.readObject(); | ||
Sendable inputAddress = (Sendable) objectInputStream.readObject(); | ||
System.out.println("BookStore: received address " + inputAddress.getPayload()); | ||
objectOutputStream.writeObject(new SendableDateTime(new Date(), "2")); | ||
Sendable inputQuit = (Sendable) objectInputStream.readObject(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/dynosesh/example/multiparty/bookstore/BuyerOne.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.dynosesh.example.multiparty.bookstore; | ||
|
||
import com.dynosesh.Sendable; | ||
import com.dynosesh.example.multiparty.bookstore.types.SendableInteger; | ||
import com.dynosesh.example.multiparty.bookstore.types.SendableString; | ||
import java.io.IOException; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.net.Socket; | ||
|
||
public class BuyerOne implements Runnable { | ||
|
||
private int port; | ||
|
||
public BuyerOne(int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
Socket socket = new Socket("localhost", port); | ||
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); | ||
objectOutputStream.flush(); | ||
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); | ||
streamsInitialised(objectOutputStream, objectInputStream); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (ClassNotFoundException e) { | ||
System.out.println("Protocol was violated on BuyerOne!"); | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
private void streamsInitialised(ObjectOutputStream objectOutputStream, | ||
ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { | ||
objectOutputStream.writeObject(new SendableString("The New Old World by Perry Anderson", | ||
"0")); | ||
Sendable quote = (Sendable) objectInputStream.readObject(); | ||
System.out.println(" BuyerOne: quote is " + quote.getPayload()); | ||
Sendable okay = (Sendable) objectInputStream.readObject(); | ||
System.out.println(" BuyerOne: received Okay"); | ||
Integer returnValue = (Integer) quote.getPayload(); | ||
objectOutputStream.writeObject(new SendableInteger(returnValue / 2, "2")); | ||
} | ||
|
||
} |
Oops, something went wrong.