0
# UI Server Management
1
2
The UI Server is the central component that manages the web-based monitoring interface for DeepLearning4J training processes. It provides a singleton server instance that coordinates data visualization and remote monitoring capabilities.
3
4
## Core Server API
5
6
### UIServer
7
8
The main abstract class for UI server management.
9
10
```java { .api }
11
public abstract class UIServer {
12
// Get singleton UI server instance
13
public static synchronized UIServer getInstance();
14
15
// Server information
16
public abstract String getAddress();
17
public abstract int getPort();
18
19
// Storage management
20
public abstract void attach(StatsStorage statsStorage);
21
public abstract void detach(StatsStorage statsStorage);
22
public abstract boolean isAttached(StatsStorage statsStorage);
23
public abstract List<StatsStorage> getStatsStorageInstances();
24
25
// Remote listener functionality
26
public abstract void enableRemoteListener();
27
public abstract void enableRemoteListener(StatsStorageRouter statsStorage, boolean attach);
28
public abstract void disableRemoteListener();
29
public abstract boolean isRemoteListenerEnabled();
30
31
// Server lifecycle
32
public abstract void stop();
33
}
34
```
35
36
### PlayUIServer Implementation
37
38
The concrete implementation using the Play Framework.
39
40
```java { .api }
41
public class PlayUIServer extends UIServer {
42
public static final int DEFAULT_UI_PORT = 9000;
43
44
public PlayUIServer();
45
public void runMain(String[] args);
46
}
47
```
48
49
## Usage Examples
50
51
### Basic Server Setup
52
53
```java
54
import org.deeplearning4j.ui.api.UIServer;
55
import org.deeplearning4j.ui.storage.InMemoryStatsStorage;
56
57
// Get the singleton UI server instance
58
UIServer uiServer = UIServer.getInstance();
59
60
// Create storage for statistics
61
InMemoryStatsStorage statsStorage = new InMemoryStatsStorage();
62
63
// Attach storage to the UI server
64
uiServer.attach(statsStorage);
65
66
// Server is now accessible at http://localhost:9000
67
System.out.println("UI Server running at: " + uiServer.getAddress());
68
```
69
70
### Managing Multiple Storage Instances
71
72
```java
73
import org.deeplearning4j.ui.api.UIServer;
74
import org.deeplearning4j.ui.storage.InMemoryStatsStorage;
75
import org.deeplearning4j.ui.storage.FileStatsStorage;
76
77
UIServer uiServer = UIServer.getInstance();
78
79
// Attach multiple storage instances
80
InMemoryStatsStorage memoryStorage = new InMemoryStatsStorage();
81
FileStatsStorage fileStorage = new FileStatsStorage(new File("training-stats.db"));
82
83
uiServer.attach(memoryStorage);
84
uiServer.attach(fileStorage);
85
86
// Check attached storage instances
87
List<StatsStorage> attachedStorage = uiServer.getStatsStorageInstances();
88
System.out.println("Number of attached storage instances: " + attachedStorage.size());
89
90
// Detach when no longer needed
91
uiServer.detach(memoryStorage);
92
```
93
94
### Remote Monitoring Setup
95
96
```java
97
import org.deeplearning4j.ui.api.UIServer;
98
import org.deeplearning4j.api.storage.impl.RemoteUIStatsStorageRouter;
99
100
UIServer uiServer = UIServer.getInstance();
101
102
// Enable remote listener with in-memory storage
103
uiServer.enableRemoteListener();
104
105
// Or with custom storage router
106
RemoteUIStatsStorageRouter remoteRouter = new RemoteUIStatsStorageRouter("http://remote-ui-server:9000");
107
uiServer.enableRemoteListener(remoteRouter, true);
108
109
// Check if remote listener is enabled
110
if (uiServer.isRemoteListenerEnabled()) {
111
System.out.println("Remote monitoring is active");
112
}
113
114
// Disable when done
115
uiServer.disableRemoteListener();
116
```
117
118
## Module Configuration
119
120
### UIModule Interface
121
122
Interface for creating custom UI modules and extensions.
123
124
```java { .api }
125
public interface UIModule {
126
List<Route> getRoutes();
127
List<Route> getCallbacks();
128
String getMenuText();
129
String getTitle();
130
}
131
```
132
133
### Route Configuration
134
135
HTTP route definitions for UI endpoints.
136
137
```java { .api }
138
public class Route {
139
public Route(String route, HttpMethod httpMethod, FunctionType functionType,
140
String functionString, String id);
141
142
public String getRoute();
143
public HttpMethod getHttpMethod();
144
public FunctionType getFunctionType();
145
public String getFunctionString();
146
public String getId();
147
}
148
```
149
150
### HTTP Methods and Function Types
151
152
```java { .api }
153
public enum HttpMethod {
154
GET, POST, PUT, DELETE
155
}
156
157
public enum FunctionType {
158
Supplier, Function, BiFunction
159
}
160
```
161
162
## Server Lifecycle
163
164
### Starting the Server
165
166
The UI server starts automatically when `getInstance()` is first called. The default port is 9000.
167
168
### Stopping the Server
169
170
```java
171
UIServer uiServer = UIServer.getInstance();
172
173
// Stop the server when application shuts down
174
uiServer.stop();
175
```
176
177
### Custom Port Configuration
178
179
```java
180
import org.deeplearning4j.ui.play.PlayUIServer;
181
182
// Create server with custom port
183
PlayUIServer server = new PlayUIServer();
184
server.runMain(new String[]{"--uiPort", "8080"});
185
```
186
187
## Utility Functions
188
189
### Browser Integration
190
191
```java { .api }
192
public class UiUtils {
193
public static void tryOpenBrowser(String path, Logger log);
194
public static void openBrowser(URI uri) throws Exception;
195
}
196
```
197
198
Usage example:
199
200
```java
201
import org.deeplearning4j.ui.UiUtils;
202
203
UIServer uiServer = UIServer.getInstance();
204
String serverAddress = uiServer.getAddress();
205
206
// Attempt to open browser automatically
207
UiUtils.tryOpenBrowser(serverAddress, LoggerFactory.getLogger(MyClass.class));
208
```
209
210
## Internationalization
211
212
### I18N Support
213
214
```java { .api }
215
public class I18N {
216
// Methods for internationalization support
217
public static String getMessage(String key);
218
public static String getMessage(String key, Object... args);
219
}
220
```