|
1 | 1 | package org.freedesktop.dbus.connections.config; |
2 | 2 |
|
| 3 | +import org.freedesktop.dbus.connections.shared.ExecutorNames; |
3 | 4 | import org.freedesktop.dbus.connections.shared.IThreadPoolRetryHandler; |
4 | 5 |
|
| 6 | +import java.util.EnumMap; |
| 7 | +import java.util.Map; |
| 8 | +import java.util.Optional; |
| 9 | + |
5 | 10 | /** |
6 | 11 | * Bean which holds configuration for {@link org.freedesktop.dbus.connections.base.ReceivingService}. |
7 | 12 | * |
8 | 13 | * @author hypfvieh |
9 | 14 | * @since 4.2.0 - 2022-07-14 |
10 | 15 | */ |
11 | 16 | public final class ReceivingServiceConfig { |
12 | | - private int signalThreadPoolSize = 1; |
13 | | - private int errorThreadPoolSize = 1; |
14 | | - private int methodCallThreadPoolSize = 4; |
15 | | - private int methodReturnThreadPoolSize = 1; |
16 | | - private int signalThreadPriority = Thread.NORM_PRIORITY; |
17 | | - private int methodCallThreadPriority = Thread.NORM_PRIORITY; |
18 | | - private int errorThreadPriority = Thread.NORM_PRIORITY; |
19 | | - private int methodReturnThreadPriority = Thread.NORM_PRIORITY; |
| 17 | + |
| 18 | + private final Map<ExecutorNames, ThreadCfg> threadConfigs = new EnumMap<>(ExecutorNames.class); |
20 | 19 |
|
21 | 20 | private IThreadPoolRetryHandler retryHandler; |
22 | 21 |
|
23 | 22 | ReceivingServiceConfig() { |
| 23 | + threadConfigs.put(ExecutorNames.SIGNAL, new ThreadCfg(1, Thread.NORM_PRIORITY, false)); |
| 24 | + threadConfigs.put(ExecutorNames.ERROR, new ThreadCfg(1, Thread.NORM_PRIORITY, false)); |
| 25 | + threadConfigs.put(ExecutorNames.METHODCALL, new ThreadCfg(4, Thread.NORM_PRIORITY, false)); |
| 26 | + threadConfigs.put(ExecutorNames.METHODRETURN, new ThreadCfg(1, Thread.NORM_PRIORITY, false)); |
24 | 27 | } |
25 | 28 |
|
26 | 29 | public int getSignalThreadPoolSize() { |
27 | | - return signalThreadPoolSize; |
| 30 | + return threadConfigs.get(ExecutorNames.SIGNAL).poolSize(); |
28 | 31 | } |
29 | 32 |
|
30 | 33 | public int getErrorThreadPoolSize() { |
31 | | - return errorThreadPoolSize; |
| 34 | + return threadConfigs.get(ExecutorNames.ERROR).poolSize(); |
32 | 35 | } |
33 | 36 |
|
34 | 37 | public int getMethodCallThreadPoolSize() { |
35 | | - return methodCallThreadPoolSize; |
| 38 | + return threadConfigs.get(ExecutorNames.METHODCALL).poolSize(); |
36 | 39 | } |
37 | 40 |
|
38 | 41 | public int getMethodReturnThreadPoolSize() { |
39 | | - return methodReturnThreadPoolSize; |
| 42 | + return threadConfigs.get(ExecutorNames.METHODRETURN).poolSize(); |
40 | 43 | } |
41 | 44 |
|
42 | 45 | public int getSignalThreadPriority() { |
43 | | - return signalThreadPriority; |
| 46 | + return threadConfigs.get(ExecutorNames.SIGNAL).priority(); |
44 | 47 | } |
45 | 48 |
|
46 | 49 | public int getMethodCallThreadPriority() { |
47 | | - return methodCallThreadPriority; |
| 50 | + return threadConfigs.get(ExecutorNames.METHODCALL).priority(); |
48 | 51 | } |
49 | 52 |
|
50 | 53 | public int getErrorThreadPriority() { |
51 | | - return errorThreadPriority; |
| 54 | + return threadConfigs.get(ExecutorNames.ERROR).priority(); |
52 | 55 | } |
53 | 56 |
|
54 | 57 | public int getMethodReturnThreadPriority() { |
55 | | - return methodReturnThreadPriority; |
| 58 | + return threadConfigs.get(ExecutorNames.METHODRETURN).priority(); |
56 | 59 | } |
57 | 60 |
|
58 | 61 | public IThreadPoolRetryHandler getRetryHandler() { |
59 | 62 | return retryHandler; |
60 | 63 | } |
61 | 64 |
|
| 65 | + public boolean isSignalVirtualThreads() { |
| 66 | + return threadConfigs.get(ExecutorNames.SIGNAL).virtual(); |
| 67 | + } |
| 68 | + |
| 69 | + public boolean isErrorVirtualThreads() { |
| 70 | + return threadConfigs.get(ExecutorNames.ERROR).virtual(); |
| 71 | + } |
| 72 | + |
| 73 | + public boolean isMethodCallVirtualThreads() { |
| 74 | + return threadConfigs.get(ExecutorNames.METHODCALL).virtual(); |
| 75 | + } |
| 76 | + |
| 77 | + public boolean isMethodReturnVirtualThreads() { |
| 78 | + return threadConfigs.get(ExecutorNames.METHODRETURN).virtual(); |
| 79 | + } |
| 80 | + |
| 81 | + public boolean isVirtual(ExecutorNames _type) { |
| 82 | + return Optional.ofNullable(_type).map(p -> threadConfigs.get(p).virtual()).orElseThrow(); |
| 83 | + } |
| 84 | + |
| 85 | + public int getPoolSize(ExecutorNames _type) { |
| 86 | + return Optional.ofNullable(_type).map(p -> threadConfigs.get(p).poolSize()).orElseThrow(); |
| 87 | + } |
| 88 | + |
| 89 | + public int getPriority(ExecutorNames _type) { |
| 90 | + return Optional.ofNullable(_type).map(p -> threadConfigs.get(p).priority()).orElseThrow(); |
| 91 | + } |
| 92 | + |
62 | 93 | void setSignalThreadPoolSize(int _signalThreadPoolSize) { |
63 | | - signalThreadPoolSize = _signalThreadPoolSize; |
| 94 | + threadConfigs.compute(ExecutorNames.SIGNAL, (t, u) -> new ThreadCfg(_signalThreadPoolSize, u.priority(), u.virtual())); |
64 | 95 | } |
65 | 96 |
|
66 | 97 | void setErrorThreadPoolSize(int _errorThreadPoolSize) { |
67 | | - errorThreadPoolSize = _errorThreadPoolSize; |
| 98 | + threadConfigs.compute(ExecutorNames.ERROR, (t, u) -> new ThreadCfg(_errorThreadPoolSize, u.priority(), u.virtual())); |
68 | 99 | } |
69 | 100 |
|
70 | 101 | void setMethodCallThreadPoolSize(int _methodCallThreadPoolSize) { |
71 | | - methodCallThreadPoolSize = _methodCallThreadPoolSize; |
| 102 | + threadConfigs.compute(ExecutorNames.METHODCALL, (t, u) -> new ThreadCfg(_methodCallThreadPoolSize, u.priority(), u.virtual())); |
72 | 103 | } |
73 | 104 |
|
74 | 105 | void setMethodReturnThreadPoolSize(int _methodReturnThreadPoolSize) { |
75 | | - methodReturnThreadPoolSize = _methodReturnThreadPoolSize; |
| 106 | + threadConfigs.compute(ExecutorNames.METHODRETURN, (t, u) -> new ThreadCfg(_methodReturnThreadPoolSize, u.priority(), u.virtual())); |
76 | 107 | } |
77 | 108 |
|
78 | 109 | void setSignalThreadPriority(int _signalThreadPriority) { |
79 | | - signalThreadPriority = _signalThreadPriority; |
| 110 | + threadConfigs.compute(ExecutorNames.SIGNAL, (t, u) -> new ThreadCfg(u.poolSize(), _signalThreadPriority, u.virtual())); |
80 | 111 | } |
81 | 112 |
|
82 | 113 | void setMethodCallThreadPriority(int _methodCallThreadPriority) { |
83 | | - methodCallThreadPriority = _methodCallThreadPriority; |
| 114 | + threadConfigs.compute(ExecutorNames.METHODCALL, (t, u) -> new ThreadCfg(u.poolSize(), _methodCallThreadPriority, u.virtual())); |
84 | 115 | } |
85 | 116 |
|
86 | 117 | void setErrorThreadPriority(int _errorThreadPriority) { |
87 | | - errorThreadPriority = _errorThreadPriority; |
| 118 | + threadConfigs.compute(ExecutorNames.ERROR, (t, u) -> new ThreadCfg(u.poolSize(), _errorThreadPriority, u.virtual())); |
88 | 119 | } |
89 | 120 |
|
90 | 121 | void setMethodReturnThreadPriority(int _methodReturnThreadPriority) { |
91 | | - methodReturnThreadPriority = _methodReturnThreadPriority; |
| 122 | + threadConfigs.compute(ExecutorNames.METHODRETURN, (t, u) -> new ThreadCfg(u.poolSize(), _methodReturnThreadPriority, u.virtual())); |
92 | 123 | } |
93 | 124 |
|
94 | 125 | void setRetryHandler(IThreadPoolRetryHandler _retryHandler) { |
95 | 126 | retryHandler = _retryHandler; |
96 | 127 | } |
97 | 128 |
|
| 129 | + void setSignalVirtualThreads(boolean _signalVirtualThreads) { |
| 130 | + threadConfigs.compute(ExecutorNames.SIGNAL, (t, u) -> new ThreadCfg(u.poolSize(), u.priority(), _signalVirtualThreads)); |
| 131 | + } |
| 132 | + |
| 133 | + void setErrorVirtualThreads(boolean _errorVirtualThreads) { |
| 134 | + threadConfigs.compute(ExecutorNames.ERROR, (t, u) -> new ThreadCfg(u.poolSize(), u.priority(), _errorVirtualThreads)); |
| 135 | + } |
| 136 | + |
| 137 | + void setMethodCallVirtualThreads(boolean _methodCallVirtualThreads) { |
| 138 | + threadConfigs.compute(ExecutorNames.METHODCALL, (t, u) -> new ThreadCfg(u.poolSize(), u.priority(), _methodCallVirtualThreads)); |
| 139 | + } |
| 140 | + |
| 141 | + void setMethodReturnVirtualThreads(boolean _methodReturnVirtualThreads) { |
| 142 | + threadConfigs.compute(ExecutorNames.METHODRETURN, (t, u) -> new ThreadCfg(u.poolSize(), u.priority(), _methodReturnVirtualThreads)); |
| 143 | + } |
| 144 | + |
| 145 | + private record ThreadCfg(int poolSize, int priority, boolean virtual) {} |
98 | 146 | } |
0 commit comments