20 namespace Lucene.Net.Store
37 private static System.String GetTime(
long startTime)
39 return "[" + (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - startTime) / 1000) +
"s] ";
43 public static void Main(System.String[] args)
48 System.Console.Out.WriteLine(
"\nUsage: java Lucene.Net.Store.LockVerifyServer port\n");
49 System.Environment.Exit(1);
52 int port = System.Int32.Parse(args[0]);
54 System.Net.Sockets.TcpListener temp_tcpListener;
55 temp_tcpListener =
new System.Net.Sockets.TcpListener(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList[0], port);
56 temp_tcpListener.Server.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Socket, System.Net.Sockets.SocketOptionName.ReuseAddress, 1);
57 temp_tcpListener.Start();
58 System.Net.Sockets.TcpListener s = temp_tcpListener;
59 System.Console.Out.WriteLine(
"\nReady on port " + port +
"...");
62 long startTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond);
66 System.Net.Sockets.TcpClient cs = s.AcceptTcpClient();
67 System.IO.Stream out_Renamed = cs.GetStream();
68 System.IO.Stream in_Renamed = cs.GetStream();
70 int id = in_Renamed.ReadByte();
71 int command = in_Renamed.ReadByte();
81 System.Console.Out.WriteLine(GetTime(startTime) +
" ERROR: id " +
id +
" got lock, but " + lockedID +
" already holds the lock");
85 else if (command == 0)
90 System.Console.Out.WriteLine(GetTime(startTime) +
" ERROR: id " +
id +
" released the lock, but " + lockedID +
" is the one holding the lock");
95 throw new System.SystemException(
"unrecognized command " + command);
97 System.Console.Out.Write(
".");
100 out_Renamed.WriteByte((System.Byte) 1);
102 out_Renamed.WriteByte((System.Byte) 0);