comparison src/goodjava/lucene/backup/BackupServer.java @ 1509:0ba144491a42

lucene.backup zip
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 17 May 2020 14:29:33 -0600
parents d80395468b4e
children 31b543826ca9
comparison
equal deleted inserted replaced
1508:86c5e7000ecf 1509:0ba144491a42
1 package goodjava.lucene.backup; 1 package goodjava.lucene.backup;
2 2
3 import java.io.File; 3 import java.io.File;
4 import java.io.OutputStream;
5 import java.io.FileOutputStream;
6 import java.io.BufferedOutputStream;
4 import java.io.IOException; 7 import java.io.IOException;
5 import java.util.Map; 8 import java.util.Map;
6 import java.net.Socket; 9 import java.net.Socket;
7 import java.net.ServerSocket; 10 import java.net.ServerSocket;
8 import java.util.concurrent.Executors; 11 import java.util.concurrent.Executors;
9 import java.util.concurrent.ExecutorService; 12 import java.util.concurrent.ExecutorService;
13 import javax.net.ssl.SSLSocket;
10 import javax.net.ssl.SSLServerSocket; 14 import javax.net.ssl.SSLServerSocket;
11 import goodjava.util.SoftCacheMap; 15 import goodjava.util.SoftCacheMap;
12 import goodjava.io.IoUtils; 16 import goodjava.io.IoUtils;
13 import goodjava.rpc.RpcServer; 17 import goodjava.rpc.RpcServer;
14 import goodjava.rpc.RpcCall; 18 import goodjava.rpc.RpcCall;
19 import goodjava.rpc.RpcClient;
20 import goodjava.rpc.RpcResult;
21 import goodjava.rpc.RpcException;
15 import goodjava.logging.Logger; 22 import goodjava.logging.Logger;
16 import goodjava.logging.LoggerFactory; 23 import goodjava.logging.LoggerFactory;
17 24
18 25
19 public class BackupServer { 26 public class BackupServer {
83 } 90 }
84 backup.handle(rpc,call); 91 backup.handle(rpc,call);
85 } 92 }
86 } 93 }
87 94
95
96 // for client
97
98 public static RpcClient rpcClient(String backupDomain) throws IOException {
99 Socket socket;
100 if( BackupServer.cipherSuites == null ) {
101 socket = new Socket(backupDomain,BackupServer.port);
102 } else {
103 socket = IoUtils.getSSLSocketFactory().createSocket(backupDomain,BackupServer.port);
104 ((SSLSocket)socket).setEnabledCipherSuites(BackupServer.cipherSuites);
105 }
106 return new RpcClient(socket);
107 }
108
109 public static void getBackup(String backupDomain,String name,File zip) throws IOException, RpcException {
110 RpcClient rpc = BackupServer.rpcClient(backupDomain);
111 RpcCall call = new RpcCall("zip",name);
112 rpc.write(call);
113 RpcResult result = rpc.read();
114 OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));
115 IoUtils.copyAll(result.in,out);
116 out.close();
117 rpc.close();
118 }
119
88 } 120 }