comparison src/fdl/AcceptHandler.java @ 3:ae7e0e92c651

*** empty log message ***
author fuchita
date Mon, 11 Feb 2008 11:54:15 +0900
parents 083a0b5e12cc
children 2023d9b31af9
comparison
equal deleted inserted replaced
2:b49e593b2502 3:ae7e0e92c651
1 1
2 package fdl; 2 package fdl;
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.net.InetAddress;
5 import java.net.InetSocketAddress;
6 import java.net.UnknownHostException;
4 import java.nio.ByteBuffer; 7 import java.nio.ByteBuffer;
5 import java.nio.channels.ClosedChannelException; 8 import java.nio.channels.ClosedChannelException;
6 import java.nio.channels.SelectionKey; 9 import java.nio.channels.SelectionKey;
7 import java.nio.channels.ServerSocketChannel; 10 import java.nio.channels.ServerSocketChannel;
8 import java.nio.channels.SocketChannel; 11 import java.nio.channels.SocketChannel;
12 import java.util.LinkedList;
9 13
10 public class AcceptHandler implements TupleHandler, PSXQueueInterface { 14 public class AcceptHandler implements TupleHandler, PSXQueueInterface {
11 //public Hashtable<Integer, Tuple> tuple_space; 15 //public Hashtable<Integer, Tuple> tuple_space;
12 public Tuple[] tuple_space; 16 public Tuple[] tuple_space;
13 17
27 = (ServerSocketChannel)key.channel(); 31 = (ServerSocketChannel)key.channel();
28 32
29 // アクセプト処理 33 // アクセプト処理
30 SocketChannel channel = serverChannel.accept(); 34 SocketChannel channel = serverChannel.accept();
31 channel.configureBlocking(false); 35 channel.configureBlocking(false);
32 System.out.println("Server: accepted "+channel.socket().getInetAddress()); 36 System.out.println("Server: accepted "+channel.socket());
37
38 //ByteBuffer command = ByteBuffer.allocate(LINDA_HEADER_SIZE);
39 //LinkedList<SocketChannel> reportCh_list = ComDebug.Report_Channellist;
40 //AcceptwishComDebug(key, command, reportCh_list);
33 41
34 42
35 //初期生成 43 //初期生成
36 if((tmpTuple = tuple_space[MAX_TUPLE-1]) == null) { 44 if((tmpTuple = tuple_space[MAX_TUPLE-1]) == null) {
37 tmpTuple = tuple_space[MAX_TUPLE-1] = new Tuple(); 45 tmpTuple = tuple_space[MAX_TUPLE-1] = new Tuple();
71 // 監視する操作は読み込みのみ 79 // 監視する操作は読み込みのみ
72 IOParam handler = new IOHandler(tuple_space); 80 IOParam handler = new IOHandler(tuple_space);
73 channel.register(key.selector(), 81 channel.register(key.selector(),
74 SelectionKey.OP_READ, 82 SelectionKey.OP_READ,
75 handler); 83 handler);
76 } 84 }
77 } 85 }