Created
March 22, 2012 02:33
-
-
Save shouichi/2155244 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Run "make" to run on normal JVM, "make jpf" to run on JPF. | |
Please edit Makefile and site.properties fiels and set correct paths of JPF and net-iocache. |
This file contains hidden or 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
RM=rm -f | |
JAVAC=javac | |
JAVAC_FLAGS=-g | |
JAVA=java | |
JAVA_FLAGS=-ea | |
JPF=~/jpf/jpf-core/bin/jpf | |
SOURCES=ServerSocketChannel.java | |
CLASSES=$(SOURCES:.java=.class) | |
CONF_FILE=$(SOURCES:.java=.jpf) | |
all: run | |
run: $(CLASSES) | |
$(JAVA) $(JAVA_FLAGS) `basename $< .class` | |
jpf: $(CLASSES) $(CONF_FILE) | |
$(JPF) $(CONF_FILE) | |
.SUFFIXES: | |
.SUFFIXES: .java .class | |
.java.class: | |
$(JAVAC) $(JAFAC_FLAG) $< | |
.PHONY: clean | |
clean: | |
$(RM) *.class |
This file contains hidden or 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
#!/bin/sh | |
curl localhost:8888 |
This file contains hidden or 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
import java.util.*; | |
import java.net.*; | |
public class ServerSocketChannel { | |
private ServerSocket ss; | |
private Queue<Socket> queue; | |
private AcceptorThread acceptor; | |
public static void main(String[] args) throws Exception { | |
ServerSocketChannel ssc = new ServerSocketChannel(); | |
ssc.socket().bind(new InetSocketAddress(8888)); | |
ssc.socket().setReuseAddress(true); | |
ssc.accept(); | |
} | |
public ServerSocketChannel() throws java.io.IOException { | |
ss = new ServerSocket(); | |
queue = new LinkedList<Socket>(); | |
acceptor = new AcceptorThread(); | |
acceptor.setDaemon(true); | |
acceptor.start(); | |
} | |
public ServerSocket socket() { | |
return ss; | |
} | |
public Socket accept() { | |
synchronized (queue) { | |
return queue.poll(); | |
} | |
} | |
class AcceptorThread extends Thread { | |
@Override | |
public void run() { | |
while (true) { | |
synchronized (ss) { | |
while (ss.isBound() == false) { | |
try { | |
ss.wait(1000); | |
} catch (InterruptedException e) {} | |
} | |
} | |
try { | |
synchronized (queue) { | |
while (queue.size() != 0) { | |
try { | |
queue.wait(100); | |
} catch (InterruptedException e) {} | |
} | |
} | |
Socket socket = ss.accept(); | |
synchronized (queue) { | |
queue.add(socket); | |
} | |
} | |
catch (Exception e) { | |
System.exit(1); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
ssc=. | |
ssc.classpath=. | |
ssc.sourcepath=. | |
site=site.properties | |
target=ServerSocketChannel | |
jpf-net-iocache.boot.peer.command=./peer.sh |
This file contains hidden or 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
jpf-core = ${user.home}/jpf/jpf-core | |
jpf-net-iocache = ${user.home}/jpf/net-iocache | |
extensions = ${jpf-core},${jpf-net-iocache} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment