-
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.
使用state模式来表示状态的变化
- Loading branch information
0 parents
commit 3057f31
Showing
14 changed files
with
1,776 additions
and
0 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
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> |
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,5 @@ | ||
/** | ||
* Created by jrj on 17-10-30. | ||
*/ | ||
public class ClusterMessage { | ||
} |
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,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()); | ||
} | ||
} |
Oops, something went wrong.