Mercurial Hosting > luan
annotate src/goodjava/lucene/backup/BackupServer.java @ 1508:86c5e7000ecf
lucene.backup checksum
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 16 May 2020 17:56:02 -0600 |
parents | d80395468b4e |
children | 0ba144491a42 |
rev | line source |
---|---|
1499 | 1 package goodjava.lucene.backup; |
2 | |
3 import java.io.File; | |
4 import java.io.IOException; | |
5 import java.util.Map; | |
6 import java.net.Socket; | |
7 import java.net.ServerSocket; | |
8 import java.util.concurrent.Executors; | |
1502 | 9 import java.util.concurrent.ExecutorService; |
1499 | 10 import javax.net.ssl.SSLServerSocket; |
11 import goodjava.util.SoftCacheMap; | |
1501 | 12 import goodjava.io.IoUtils; |
1499 | 13 import goodjava.rpc.RpcServer; |
14 import goodjava.rpc.RpcCall; | |
15 import goodjava.logging.Logger; | |
16 import goodjava.logging.LoggerFactory; | |
17 | |
18 | |
19 public class BackupServer { | |
20 private static final Logger logger = LoggerFactory.getLogger(BackupServer.class); | |
21 | |
22 public static int port = 9101; | |
23 public static String[] cipherSuites = new String[] { | |
24 "TLS_DH_anon_WITH_AES_128_GCM_SHA256", | |
25 "TLS_DH_anon_WITH_AES_128_CBC_SHA256", | |
26 "TLS_ECDH_anon_WITH_AES_128_CBC_SHA", | |
27 "TLS_DH_anon_WITH_AES_128_CBC_SHA", | |
28 "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", | |
29 "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", | |
30 "TLS_ECDH_anon_WITH_RC4_128_SHA", | |
31 "SSL_DH_anon_WITH_RC4_128_MD5", | |
32 "SSL_DH_anon_WITH_DES_CBC_SHA", | |
33 "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", | |
34 "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", | |
35 }; | |
36 | |
37 private final File backupDir; | |
1502 | 38 private static final ExecutorService threadPool = Executors.newCachedThreadPool(); |
1499 | 39 private static final Map<String,Backup> backups = new SoftCacheMap<String,Backup>(); |
40 | |
1501 | 41 public BackupServer(File backupDir) throws IOException { |
1499 | 42 this.backupDir = backupDir; |
1501 | 43 IoUtils.mkdirs(backupDir); |
1499 | 44 } |
45 | |
46 public synchronized void start() throws IOException { | |
47 final ServerSocket ss; | |
48 if( cipherSuites == null ) { | |
49 ss = new ServerSocket(port); | |
50 } else { | |
1506
d80395468b4e
ssl security in code
Franklin Schmidt <fschmidt@gmail.com>
parents:
1502
diff
changeset
|
51 ss = IoUtils.getSSLServerSocketFactory().createServerSocket(port); |
1499 | 52 ((SSLServerSocket)ss).setEnabledCipherSuites(cipherSuites); |
53 } | |
54 threadPool.execute(new Runnable(){public void run() { | |
55 try { | |
56 while(!threadPool.isShutdown()) { | |
57 final Socket socket = ss.accept(); | |
58 threadPool.execute(new Runnable(){public void run() { | |
59 handle(socket); | |
60 }}); | |
61 } | |
62 } catch(IOException e) { | |
63 logger.error("",e); | |
64 } | |
65 }}); | |
66 logger.info("started server on port "+port); | |
67 } | |
68 | |
69 private void handle(Socket socket) { | |
70 RpcServer rpc = new RpcServer(socket); | |
71 while( !rpc.isClosed() ) { | |
72 RpcCall call = rpc.read(); | |
73 if( call == null ) | |
74 break; | |
75 String name = (String)call.args[0]; | |
76 Backup backup; | |
77 synchronized(backups) { | |
78 backup = backups.get(name); | |
79 if( backup == null ) { | |
80 backup = new Backup(new File(backupDir,name)); | |
81 backups.put(name,backup); | |
82 } | |
83 } | |
84 backup.handle(rpc,call); | |
85 } | |
86 } | |
87 | |
88 } |