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 java.net.Socket;
20 import org.apache.logging.log4j.core.Core;
21 import org.apache.logging.log4j.core.config.plugins.Plugin;
22 import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
23 import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
24 import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
25 import org.apache.logging.log4j.core.util.Builder;
26
27
28
29
30
31
32
33 @Plugin(name = "SocketPerformancePreferences", category = Core.CATEGORY_NAME, printObject = true)
34 public class SocketPerformancePreferences implements Builder<SocketPerformancePreferences>, Cloneable {
35
36 @PluginBuilderFactory
37 public static SocketPerformancePreferences newBuilder() {
38 return new SocketPerformancePreferences();
39 }
40
41 @PluginBuilderAttribute
42 @Required
43 private int bandwidth;
44
45 @PluginBuilderAttribute
46 @Required
47 private int connectionTime;
48
49 @PluginBuilderAttribute
50 @Required
51 private int latency;
52
53 public void apply(final Socket socket) {
54 socket.setPerformancePreferences(connectionTime, latency, bandwidth);
55 }
56
57 @Override
58 public SocketPerformancePreferences build() {
59 try {
60 return (SocketPerformancePreferences) clone();
61 } catch (final CloneNotSupportedException e) {
62 throw new IllegalStateException(e);
63 }
64 }
65
66 public int getBandwidth() {
67 return bandwidth;
68 }
69
70 public int getConnectionTime() {
71 return connectionTime;
72 }
73
74 public int getLatency() {
75 return latency;
76 }
77
78 public void setBandwidth(final int bandwidth) {
79 this.bandwidth = bandwidth;
80 }
81
82 public void setConnectionTime(final int connectionTime) {
83 this.connectionTime = connectionTime;
84 }
85
86 public void setLatency(final int latency) {
87 this.latency = latency;
88 }
89
90 @Override
91 public String toString() {
92 return "SocketPerformancePreferences [bandwidth=" + bandwidth + ", connectionTime=" + connectionTime
93 + ", latency=" + latency + "]";
94 }
95
96 }