Skip to content

Commit

Permalink
完成了时间轮,作为定时器的实现
Browse files Browse the repository at this point in the history
使用state模式来表示状态的变化
  • Loading branch information
jrjsjtu committed Oct 31, 2017
0 parents commit 3057f31
Show file tree
Hide file tree
Showing 14 changed files with 1,776 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>JrjPersonal</groupId>
<artifactId>EasyRaft</artifactId>
<version>1.0-SNAPSHOT</version>


</project>
5 changes: 5 additions & 0 deletions src/main/java/ClusterMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Created by jrj on 17-10-30.
*/
public class ClusterMessage {
}
58 changes: 58 additions & 0 deletions src/main/java/SimpleChat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;
import org.jgroups.View;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.AtomicInteger;

public class SimpleChat extends ReceiverAdapter {
JChannel channel;
String user_name=System.getProperty("user.name", "n/a");
private AtomicInteger atomicInteger;
private final static int clusterSize = 3;
private void start() throws Exception {
channel=new JChannel();
channel.setReceiver(this);
channel.connect("ChatCluster");
eventLoop();
channel.close();
atomicInteger = new AtomicInteger(0);
}

public static void main(String[] args) throws Exception {
new SimpleChat().start();
}

private void eventLoop() {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
while(true) {
try {
System.out.print("> "); System.out.flush();
String line=in.readLine().toLowerCase();
if(line.startsWith("quit") || line.startsWith("exit"))
break;
line="[" + user_name + "] " + line;
Message msg=new Message(null, null, line);
channel.send(msg);
} catch(Exception e) {
e.printStackTrace();
}
}
}

// s
@Override
public void viewAccepted(View new_view) {
if (new_view.size()>=(clusterSize/2+1)){

}
System.out.println("** view: " + new_view);
}

@Override
public void receive(Message msg) {
System.out.println(msg.getSrc() + ": " + msg.getObject());
}
}
Loading

0 comments on commit 3057f31

Please sign in to comment.