public void run System out println Selector Started int totalKeys Iter

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
public void run()
{
System.out.println("Selector Started");
int totalKeys = 0;
Iterator<SelectionKey> iter;
SelectionKey key;
MMOConnection<T> con;
FastList.Node<MMOConnection<T>> n, end, temp;
// main loop
for (;;)
{
// check for shutdown
if (this.isShuttingDown())
{
this.closeSelectorThread();
break;
}
try
{
totalKeys = this.getSelector().selectNow();
}
catch (IOException e)
{
//TODO logging
e.printStackTrace();
}
//System.out.println("Selector Selected "+totalKeys);
if (totalKeys > 0)
{
Set<SelectionKey> keys = this.getSelector().selectedKeys();
iter = keys.iterator();
while (iter.hasNext())
{
key = iter.next();
iter.remove();
switch (key.readyOps())
{
case SelectionKey.OP_CONNECT:
this.finishConnection(key);
break;
case SelectionKey.OP_ACCEPT:
this.acceptConnection(key); // <----- remove con
break;
case SelectionKey.OP_READ:
this.readPacket(key);
break;
case SelectionKey.OP_WRITE:
this.writePacket(key);
break;
case SelectionKey.OP_READ | SelectionKey.OP_WRITE:
this.writePacket(key);
// key might have been invalidated on writePacket
if (key.isValid())
this.readPacket(key);
break;
}
}
}
// process pending close
for (n = this.getPendingClose().head(), end = this.getPendingClose().tail(); (n = n.getNext()) != end;)
{
con = n.getValue();
if (con.getSendQueue().isEmpty())
{
temp = n.getPrevious();
this.getPendingClose().delete(n);
n = temp;
this.closeConnectionImpl(con);
}
}
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
protected void acceptConnection(SelectionKey key)
{
ServerSocketChannel ssc = (ServerSocketChannel) key.channel();
SocketChannel sc;
try
{
if((sc = ssc.accept()) != null)
{
while (true)
{
if(this.getAcceptFilter() == null || this.getAcceptFilter().accept(sc))
{
//configure
sc.configureBlocking(false);
sc.socket().setTrafficClass(0);
sc.socket().setTcpNoDelay(false);
sc.socket().setKeepAlive(false);
SelectionKey clientKey = sc.register(this.getSelector(), SelectionKey.OP_READ);
clientKey.attach(this.getClientFactory().create(new MMOConnection<T>(this, sc, clientKey)));
}
else
{
sc.socket().close();
}
}
}
else
{
System.out.println("Made in attack server for modifications divane.");
}
}
catch (IOException e)
{
e.printStackTrace();
}
}