1
package org.apache.lucene.store;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.net.ServerSocket;
21
import java.net.Socket;
22
import java.io.OutputStream;
23
import java.io.InputStream;
24
import java.io.IOException;
27
* Simple standalone server that must be running when you
28
* use {@link VerifyingLockFactory}. This server simply
29
* verifies at most one process holds the lock at a time.
30
* Run without any args to see usage.
32
* @see VerifyingLockFactory
36
public class LockVerifyServer {
38
private static String getTime(long startTime) {
39
return "[" + ((System.currentTimeMillis()-startTime)/1000) + "s] ";
42
public static void main(String[] args) throws IOException {
44
if (args.length != 1) {
45
System.out.println("\nUsage: java org.apache.lucene.store.LockVerifyServer port\n");
49
final int port = Integer.parseInt(args[0]);
51
ServerSocket s = new ServerSocket(port);
52
s.setReuseAddress(true);
53
System.out.println("\nReady on port " + port + "...");
56
long startTime = System.currentTimeMillis();
59
Socket cs = s.accept();
60
OutputStream out = cs.getOutputStream();
61
InputStream in = cs.getInputStream();
64
int command = in.read();
72
System.out.println(getTime(startTime) + " ERROR: id " + id + " got lock, but " + lockedID + " already holds the lock");
75
} else if (command == 0) {
78
System.out.println(getTime(startTime) + " ERROR: id " + id + " released the lock, but " + lockedID + " is the one holding the lock");
82
throw new RuntimeException("unrecognized command " + command);
84
System.out.print(".");