Permalink
Browse files

Skeleton Created Successfully

  • Loading branch information...
1 parent 05a84d5 commit e63f211fedec6d68f09d9083311d3038c4ba4dae @navaneethrameshan navaneethrameshan committed Sep 30, 2011
@@ -2,7 +2,7 @@
import se.sics.kompics.*;
-public class JoinResponse extends Response
+public class JoinResponse extends Response
{
String message;
@@ -0,0 +1,12 @@
+package Events;
+
+import se.sics.kompics.Request;
+import se.sics.kompics.Response;
+
+public class LatestPostResponse extends Response {
+
+ public LatestPostResponse(Request request){
+ super(request);
+ }
+
+}
View
@@ -1,5 +1,7 @@
package Events;
-public class NewPost {
+import se.sics.kompics.Event;
+
+public class NewPost extends Event {
}
View
@@ -1,5 +1,7 @@
package Events;
-public class NewTopic {
+import se.sics.kompics.Event;
+
+public class NewTopic extends Event{
}
@@ -0,0 +1,9 @@
+package Events;
+
+import se.sics.kompics.Request;
+
+public class RegisterRequest extends Request
+{
+
+
+}
@@ -0,0 +1,30 @@
+package Events;
+
+import se.sics.kompics.Request;
+import se.sics.kompics.Response;
+
+public class RegisterResponse extends Response {
+
+ int registrationNumber;
+
+ public RegisterResponse(Request request){
+ super(request);
+ }
+
+ /**
+ * @return the registrationNumber
+ */
+ public int getRegistrationNumber() {
+ return registrationNumber;
+ }
+
+ /**
+ * @param registrationNumber the registrationNumber to set
+ */
+ public void setRegistrationNumber(int registrationNumber) {
+ this.registrationNumber = registrationNumber;
+ }
+
+
+
+}
View
@@ -1,69 +1,93 @@
package Task1;
-import src.*;
-
-import java.util.HashMap;
-import java.util.Random;
-import java.util.UUID;
-import java.util.Vector;
-
+import ports.NodePort;
import Events.InitEvent;
+import Events.JoinRequest;
+import Events.JoinResponse;
+import Events.LatestPostResponse;
+import Events.NewPost;
+import Events.NewTopic;
+import Events.RegisterRequest;
+import Events.RegisterResponse;
import se.sics.kompics.ComponentDefinition;
import se.sics.kompics.Handler;
-import se.sics.kompics.address.Address;
-import se.sics.kompics.network.Network;
-import se.sics.kompics.p2p.bootstrap.P2pBootstrap;
-import se.sics.kompics.p2p.bootstrap.client.BootstrapClient;
-import se.sics.kompics.p2p.bootstrap.client.BootstrapClientInit;
-import se.sics.kompics.p2p.fd.FailureDetector;
-import se.sics.kompics.p2p.fd.ping.PingFailureDetector;
-import se.sics.kompics.p2p.fd.ping.PingFailureDetectorInit;
-import se.sics.kompics.timer.Timer;
+import se.sics.kompics.Positive;
+import se.sics.kompics.Start;
public class Client extends ComponentDefinition
{
-
- int rand;
+
+ Positive<NodePort> clientPort = requires(NodePort.class);
+ int myRegistrationNumber;
public Client()
{
- //fdRequests = new HashMap<Address, UUID>();
- //fdPeers = new HashMap<Address, PeerAddress>();
- //bootstrap = create(BootstrapClient.class);
- rand = new Random(System.currentTimeMillis());
-
- fd = create(PingFailureDetector.class);
-
- connect(network, fd.getNegative(Network.class));
- connect(network, bootstrap.getNegative(Network.class));
- connect(timer, fd.getNegative(Timer.class));
- connect(timer, bootstrap.getNegative(Timer.class));
-
- subscribe(handleInit, control);
- subscribe(handleJoinResponse, msPeerPort);
- subscribe(handleLatestPostReponse, timer);
- subscribe(handleNewPost, fd.getPositive(FailureDetector.class));
- subscribe(handle, network);
+ // connect channels and then define subscription for handlers.
+ subscribe(handleInit, control);
+ subscribe(handleJoinResponse,clientPort);
+ subscribe(handleNewTopic,clientPort);
+ subscribe(handleNewPost,clientPort );
+ subscribe(handleLatestPostsResponse,clientPort );
+ subscribe(handleRegisterResponse,clientPort );
}
- Handler<InitEvent> handleInit = new Handler<InitEvent>() {
- public void handle(InitEvent init) {
+ //-------------------------------------------------------------------
+ // This handler initiates the Peer component.
+ //-------------------------------------------------------------------
+ Handler<Start> handleInit = new Handler<Start>() {
+ public void handle(Start init)
+ {
+ System.out.println("Client started..");
+ trigger(new RegisterRequest(), clientPort);
- /*
- peerSelf = init.getMSPeerSelf();
- self = peerSelf.getPeerAddress();
- friends = new Vector<PeerAddress>();
- msgPeriod = init.getMSConfiguration().getSnapshotPeriod();
+
+
+ }
+ };
+
+ Handler<JoinResponse> handleJoinResponse = new Handler<JoinResponse>() {
+ public void handle(JoinResponse event)
+ {
+ System.out.println("Client No: "+myRegistrationNumber+ " Rec Message From Server..");
+ }
+ };
+
+ Handler<NewTopic> handleNewTopic = new Handler<NewTopic>() {
+ public void handle(NewTopic event)
+ {
+
+ }
+ };
+
+ Handler<NewPost> handleNewPost = new Handler<NewPost>() {
+ public void handle(NewPost event)
+ {
- viewSize = init.getMSConfiguration().getViewSize();
+ }
+ };
+
+ Handler<LatestPostResponse> handleLatestPostsResponse = new Handler<LatestPostResponse>() {
+ public void handle(LatestPostResponse event)
+ {
+
+ }
+ };
+
+ Handler<RegisterResponse> handleRegisterResponse = new Handler<RegisterResponse>() {
+ public void handle(RegisterResponse event)
+ {
+ myRegistrationNumber = event.getRegistrationNumber();
+ }
+ };
+
+ /* Handler<PeerFailureSuspicion> handleClientFailureSuspicion = new Handler<PeerFailureSuspicion>() {
+ public void handle(PeerFailureSuspicion event)
+ {
- trigger(new BootstrapClientInit(self, init.getBootstrapConfiguration()), bootstrap.getControl());
- trigger(new PingFailureDetectorInit(self, init.getFdConfiguration()), fd.getControl());
- */
- }
- };
+ }
+ }; */
}
@@ -1,6 +1,5 @@
package Task1;
-import src.*;
import java.io.File;
import java.io.IOException;
View
@@ -0,0 +1,32 @@
+package Task1;
+
+
+import ports.NodePort;
+import se.sics.kompics.Channel;
+import se.sics.kompics.Component;
+import se.sics.kompics.ComponentDefinition;
+import se.sics.kompics.Handler;
+import se.sics.kompics.Kompics;
+import se.sics.kompics.Start;
+public class MainClass extends ComponentDefinition {
+
+ Component server, client1 , client2;
+ Channel c1,c2;
+
+ public MainClass()
+ {
+ server=create(Server.class);
+ client1=create(Client.class);
+ client2=create(Client.class);
+ c1=connect(server.provided(NodePort.class), client1.required(NodePort.class));
+ c2=connect(server.provided(NodePort.class), client2.required(NodePort.class));
+ //trigger(new InitEvent(), Control);
+ }
+
+ public static void main(String[] args)
+ {
+ Kompics.createAndStart(MainClass.class);
+
+ }
+
+}
View
@@ -1,10 +1,10 @@
package Task1;
import Events.*;
-
-import id2210.system.peer.PeerAddress;
+import server.*;
import java.util.Random;
import java.util.Vector;
+import ports.*;
import se.sics.kompics.*;
import se.sics.kompics.address.Address;
@@ -17,37 +17,25 @@
import se.sics.kompics.p2p.fd.ping.PingFailureDetector;
import se.sics.kompics.p2p.fd.ping.PingFailureDetectorInit;
import se.sics.kompics.timer.Timer;
-import src.*;
public class Server extends ComponentDefinition
{
-
- Address myAddress;
- PeerAddress myPeerAdress;
- Component fd;
- Random rand;
+ Negative<NodePort> serverPort = provides(NodePort.class);
+ RegisterClient registration =new RegisterClient();
public Server()
{
- //fdRequests = new HashMap<Address, UUID>();
- //fdPeers = new HashMap<Address, PeerAddress>();
- //server=Configuration.server;
- //bootStrapServer= create(BootstrapServer.class);
-
- fd = create(PingFailureDetector.class);
- rand = new Random(System.currentTimeMillis());
+
+ //connect(network, fd.getNegative(Network.class));
- connect(network, fd.getNegative(Network.class));
- connect(network, bootstrap.getNegative(Network.class));
- connect(timer, fd.getNegative(Timer.class));
- connect(timer, bootstrap.getNegative(Timer.class));
subscribe(handleInit, control);
- subscribe(handleJoinRequest, );
- subscribe(handleCreateTopic, );
- subscribe(handleCreatePost, );
- subscribe(handleLatestPostsRequest, );
- subscribe(handleClientFailureSuspicion, fd.getPositive(FailureDetector.class));
+ subscribe(handleJoinRequest,serverPort);
+ subscribe(handleCreateTopic,serverPort);
+ subscribe(handleCreatePost,serverPort );
+ subscribe(handleLatestPostsRequest,serverPort );
+ subscribe(handleRegisterRequest,serverPort );
+ // subscribe(handleClientFailureSuspicion, fd.getPositive(FailureDetector.class));
}
@@ -56,26 +44,18 @@ public Server()
//-------------------------------------------------------------------
// This handler initiates the Peer component.
//-------------------------------------------------------------------
- Handler<InitEvent> handleInit = new Handler<InitEvent>() {
- public void handle(InitEvent init) {
- /*
- peerSelf = init.getMSPeerSelf();
- self = peerSelf.getPeerAddress();
- friends = new Vector<PeerAddress>();
- msgPeriod = init.getMSConfiguration().getSnapshotPeriod();
-
- viewSize = init.getMSConfiguration().getViewSize();
-
- trigger(new BootstrapClientInit(self, init.getBootstrapConfiguration()), bootstrap.getControl());
- trigger(new PingFailureDetectorInit(self, init.getFdConfiguration()), fd.getControl());
- */
+ Handler<Start> handleInit = new Handler<Start>() {
+ public void handle(Start init)
+ {
+ System.out.println("Server started..");
}
};
Handler<JoinRequest> handleJoinRequest = new Handler<JoinRequest>() {
public void handle(JoinRequest event)
{
-
+ System.out.println("Server rec message from client.."+ event.getMessage());
+ trigger(new JoinResponse(event), serverPort);
}
};
@@ -100,10 +80,19 @@ public void handle(LatestPostsRequest event)
}
};
- Handler<PeerFailureSuspicion> handleClientFailureSuspicion = new Handler<PeerFailureSuspicion>() {
+ Handler<RegisterRequest> handleRegisterRequest = new Handler<RegisterRequest>() {
+ public void handle(RegisterRequest event)
+ {
+ RegisterResponse response= new RegisterResponse(event);
+ response.setRegistrationNumber(registration.getClientID());
+ trigger(response, serverPort);
+ }
+ };
+
+ /* Handler<PeerFailureSuspicion> handleClientFailureSuspicion = new Handler<PeerFailureSuspicion>() {
public void handle(PeerFailureSuspicion event)
{
}
- };
+ }; */
}
Oops, something went wrong.

0 comments on commit e63f211

Please sign in to comment.