1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.core.net;
18
19 import org.apache.logging.log4j.core.appender.ManagerFactory;
20
21 import java.io.OutputStream;
22
23
24
25
26 public class DatagramSocketManager extends AbstractSocketManager {
27
28 private static final DatagramSocketManagerFactory factory = new DatagramSocketManagerFactory();
29
30
31
32
33
34
35
36
37 protected DatagramSocketManager(OutputStream os, String name, String host, int port) {
38 super(name, os, null, host, port);
39 }
40
41
42
43
44
45
46
47 public static DatagramSocketManager getSocketManager(String host, int port) {
48 if (host == null || host.length() == 0) {
49 throw new IllegalArgumentException("A host name is required");
50 }
51 if (port <= 0) {
52 throw new IllegalArgumentException("A port value is required");
53 }
54 return (DatagramSocketManager) getManager("UDP:" + host + ":" + port, new FactoryData(host, port), factory
55 );
56 }
57
58
59
60
61 private static class FactoryData {
62 private String host;
63 private int port;
64
65 public FactoryData(String host, int port) {
66 this.host = host;
67 this.port = port;
68 }
69 }
70
71
72
73
74 private static class DatagramSocketManagerFactory implements ManagerFactory<DatagramSocketManager, FactoryData> {
75
76 public DatagramSocketManager createManager(String name, FactoryData data) {
77 OutputStream os = new DatagramOutputStream(data.host, data.port);
78 return new DatagramSocketManager(os, name, data.host, data.port);
79 }
80 }
81 }