44 * @date 2023/3/23
55 */
66
7- import common .util .FileScanner ;
8- import common .util .PropertyParser ;
97import thread .BroadcastReceiverThread ;
108import thread .Server ;
11- import thread .ServerThread ;
129
13- import java .io .IOException ;
1410import java .net .InetAddress ;
1511import java .net .NetworkInterface ;
1612import java .net .Socket ;
17- import java .net .UnknownHostException ;
1813import java .util .*;
1914import java .util .concurrent .ConcurrentHashMap ;
2015
3025public class Cache {
3126 public static ConcurrentHashMap <String , List <String >> ipRecourceMap = new ConcurrentHashMap <>();
3227 public static HashSet <String > ipTable = new HashSet <>();
33-
34- public static HashMap <String , Socket > socketPool = new HashMap <>();
35-
3628 public static String localHost ;
3729
3830 static {
@@ -54,7 +46,6 @@ public static String getLocalHostExactAddress() {
5446 continue ;
5547 }
5648 if (currentAddr .getHostAddress ().contains (":" )) {
57- // IPv6 address
5849 continue ;
5950 }
6051 if (currentAddr .isSiteLocalAddress ()) {
@@ -69,16 +60,6 @@ public static String getLocalHostExactAddress() {
6960 return null ;
7061 }
7162
72- public static Socket getSocketByIp (String ip ) throws IOException {
73- if (socketPool .containsKey (ip )) {
74- return socketPool .get (ip );
75- } else {
76- Socket socket = new Socket (ip , 11223 );
77- socketPool .put (ip , socket );
78- return socket ;
79- }
80- }
81-
8263 public static BroadcastReceiverThread broadcastReceiverThread ;
8364
8465 public static Server serverThread ;
@@ -89,23 +70,6 @@ public static boolean checkThread(String ip) {
8970 return serverThreadMap .containsKey (ip );
9071 }
9172
92- public static void stopAllThread () {
93- broadcastReceiverThread .stop ();
94- for (String ip : serverThreadMap .keySet ()) {
95- try {
96- serverThreadMap .get (ip ).close ();
97- } catch (Exception e ) {
98- e .printStackTrace ();
99- }
100-
101- }
102-
103- try {
104- serverThread .stop ();
105- } catch (IOException e ) {
106- e .printStackTrace ();
107- }
108- }
10973
11074 public static void add (String ip , List <String > resources ) {
11175 ipTable .add (ip );
@@ -117,22 +81,4 @@ public static void clear(String ip) {
11781 ipRecourceMap .remove (ip );
11882 }
11983
120- public static void printResources () {
121- HashSet <String > fileSet = new HashSet <>();
122- for (String ip : ipRecourceMap .keySet ()) {
123- fileSet .addAll (ipRecourceMap .get (ip ));
124- }
125- for (String file : fileSet ) {
126- System .out .println (file );
127- }
128- }
129-
130- public static String getAvailableIp (String file ) {
131- for (String ip : ipRecourceMap .keySet ()) {
132- if (ipRecourceMap .get (ip ).contains (file )) {
133- return ip ;
134- }
135- }
136- return null ;
137- }
13884}
0 commit comments