0
# Core Management
1
2
Core management provides the primary interfaces for creating, configuring, and managing Siddhi applications. The main entry points are SiddhiManager for global management and SiddhiAppRuntime for individual application lifecycle control.
3
4
## SiddhiManager
5
6
The main interface class for interacting with Siddhi as a library. This is the primary entry point for all Siddhi operations and serves as the factory for creating and managing SiddhiAppRuntime instances.
7
8
```java { .api }
9
public class SiddhiManager {
10
// Constructors
11
public SiddhiManager();
12
13
// Core Operations
14
public SiddhiAppRuntime createSiddhiAppRuntime(String siddhiApp);
15
public SiddhiAppRuntime createSiddhiAppRuntime(SiddhiApp siddhiApp);
16
public SiddhiAppRuntime getSiddhiAppRuntime(String siddhiAppName);
17
18
// Validation
19
public void validateSiddhiApp(String siddhiApp);
20
public void validateSiddhiApp(SiddhiApp siddhiApp);
21
22
// Configuration Management
23
public void setPersistenceStore(PersistenceStore persistenceStore);
24
public void setSinkHandlerManager(SinkHandlerManager sinkHandlerManager);
25
public void setSourceHandlerManager(SourceHandlerManager sourceHandlerManager);
26
public void setRecordTableHandlerManager(RecordTableHandlerManager recordTableHandlerManager);
27
public void setConfigManager(ConfigManager configManager);
28
public void setStatisticsConfiguration(StatisticsConfiguration statisticsConfiguration);
29
public void setDataSource(String dataSourceName, DataSource dataSource);
30
public void setIncrementalPersistenceStore(IncrementalPersistenceStore incrementalPersistenceStore);
31
32
// Extension Management
33
public void setExtension(String name, Class clazz);
34
public Map<String, Class> getExtensions();
35
public void removeExtension(String name);
36
37
// Runtime Management
38
public Map<String, SiddhiAppRuntime> getSiddhiAppRuntimeMap();
39
public void shutdown();
40
41
// State Management
42
public void persist();
43
public void restoreLastState();
44
public String getLastRevision(String siddhiAppName);
45
}
46
```
47
48
### Usage Example
49
50
```java
51
// Create SiddhiManager with default configuration
52
SiddhiManager siddhiManager = new SiddhiManager();
53
54
// Set up custom configurations
55
siddhiManager.setPersistenceStore(new FilePersistenceStore("./state"));
56
siddhiManager.setStatisticsConfiguration(new StatisticsConfiguration(statisticsFactory));
57
58
// Register custom extensions
59
siddhiManager.setExtension("customFunction", CustomFunctionExecutor.class);
60
61
// Create Siddhi application
62
String siddhiApp = "define stream InputStream (name string, age int); " +
63
"@info(name = 'query1') " +
64
"from InputStream select name, age insert into OutputStream;";
65
66
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
67
68
// Validate before creating (optional)
69
siddhiManager.validateSiddhiApp(siddhiApp);
70
71
// Shutdown
72
siddhiManager.shutdown();
73
```
74
75
## SiddhiAppRuntime
76
77
Represents a runtime instance of a Siddhi application with complete lifecycle management. Each SiddhiAppRuntime corresponds to one Siddhi application and provides access to its streams, queries, and runtime operations.
78
79
```java { .api }
80
public class SiddhiAppRuntime {
81
// Basic Properties
82
public String getName();
83
84
// Definition Access
85
public Map<String, StreamDefinition> getStreamDefinitionMap();
86
public Map<String, TableDefinition> getTableDefinitionMap();
87
public Map<String, WindowDefinition> getWindowDefinitionMap();
88
public Map<String, AggregationDefinition> getAggregationDefinitionMap();
89
public Set<String> getQueryNames();
90
public Map<String, StreamDefinition> getPartitionedInnerStreamDefinitionMap();
91
92
// Input/Output Management
93
public InputHandler getInputHandler(String streamId);
94
public void addCallback(String streamId, StreamCallback streamCallback);
95
public void addCallback(String queryName, QueryCallback callback);
96
97
// Store Queries
98
public Event[] query(String storeQuery);
99
public Event[] query(StoreQuery storeQuery);
100
public Attribute[] getStoreQueryOutputAttributes(String storeQuery);
101
102
// Source/Sink Access
103
public Collection<List<Source>> getSources();
104
public Collection<List<Sink>> getSinks();
105
public Collection<Table> getTables();
106
107
// Lifecycle Management
108
public void start();
109
public void startWithoutSources();
110
public void startSources();
111
public void shutdown();
112
113
// Debugging
114
public SiddhiDebugger debug();
115
116
// State Management
117
public PersistenceReference persist();
118
public byte[] snapshot();
119
public void restore(byte[] snapshot);
120
public void restoreRevision(String revision);
121
public void restoreLastRevision();
122
public void clearAllRevisions();
123
124
// Exception Handling
125
public void handleExceptionWith(ExceptionHandler<Object> exceptionHandler);
126
public void handleRuntimeExceptionWith(ExceptionListener exceptionListener);
127
128
// Statistics and Monitoring
129
public Level getRootMetricsLevel();
130
public void enableStats(Level level);
131
132
// Advanced Features
133
public void enablePlayBack(boolean playBackEnabled, Long idleTime, Long incrementInMilliseconds);
134
public void setPurgingEnabled(boolean purgingEnabled);
135
}
136
```
137
138
### Usage Example
139
140
```java
141
// Create runtime from SiddhiManager
142
SiddhiAppRuntime runtime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
143
144
// Access runtime information
145
System.out.println("App name: " + runtime.getName());
146
System.out.println("Query names: " + runtime.getQueryNames());
147
148
// Set up input handling
149
InputHandler inputHandler = runtime.getInputHandler("StockStream");
150
151
// Add callbacks for output
152
runtime.addCallback("FilteredStream", new StreamCallback() {
153
@Override
154
public void receive(Event[] events) {
155
// Handle filtered events
156
}
157
});
158
159
// Start runtime
160
runtime.start();
161
162
// Send events
163
inputHandler.send(new Object[]{"IBM", 100.0});
164
165
// Execute store query
166
Event[] results = runtime.query("from StockTable select symbol, price");
167
168
// Enable statistics
169
runtime.enableStats(Level.BASIC);
170
171
// Take snapshot for backup
172
byte[] snapshot = runtime.snapshot();
173
174
// Shutdown
175
runtime.shutdown();
176
```
177
178
## Configuration Classes
179
180
### SiddhiContext
181
182
Context information holder associated with SiddhiManager containing global configurations and extension management.
183
184
```java { .api }
185
public class SiddhiContext {
186
// Constructors
187
public SiddhiContext();
188
189
// Extension Management
190
public Map<String, Class> getSiddhiExtensions();
191
public Map<String, ExtensionHolder> getExtensionHolderMap();
192
193
// Persistence Configuration
194
public PersistenceStore getPersistenceStore();
195
public void setPersistenceStore(PersistenceStore persistenceStore);
196
public IncrementalPersistenceStore getIncrementalPersistenceStore();
197
public void setIncrementalPersistenceStore(IncrementalPersistenceStore incrementalPersistenceStore);
198
199
// Manager Configuration
200
public ConfigManager getConfigManager();
201
public void setConfigManager(ConfigManager configManager);
202
public SinkHandlerManager getSinkHandlerManager();
203
public void setSinkHandlerManager(SinkHandlerManager sinkHandlerManager);
204
public SourceHandlerManager getSourceHandlerManager();
205
public void setSourceHandlerManager(SourceHandlerManager sourceHandlerManager);
206
public RecordTableHandlerManager getRecordTableHandlerManager();
207
public void setRecordTableHandlerManager(RecordTableHandlerManager recordTableHandlerManager);
208
209
// Data Source Management
210
public DataSource getSiddhiDataSource(String dataSourceName);
211
public void addSiddhiDataSource(String dataSourceName, DataSource dataSource);
212
213
// Statistics Configuration
214
public StatisticsConfiguration getStatisticsConfiguration();
215
public void setStatisticsConfiguration(StatisticsConfiguration statisticsConfiguration);
216
217
// Exception Handling
218
public ExceptionHandler getDefaultDisrupterExceptionHandler();
219
}
220
```
221
222
### StatisticsConfiguration
223
224
Configuration holder for Siddhi statistics module providing integration with monitoring systems.
225
226
```java { .api }
227
public class StatisticsConfiguration {
228
// Constructor
229
public StatisticsConfiguration(StatisticsTrackerFactory factory);
230
231
// Configuration Access
232
public StatisticsTrackerFactory getFactory();
233
public String getMetricPrefix();
234
public void setMetricPrefix(String metricPrefix);
235
}
236
```
237
238
## Types
239
240
```java { .api }
241
public interface SiddhiApp {
242
// Parsed representation of Siddhi application
243
}
244
245
public interface StreamDefinition extends AbstractDefinition {
246
// Definition of a stream
247
}
248
249
public interface TableDefinition extends AbstractDefinition {
250
// Definition of a table
251
}
252
253
public interface WindowDefinition extends AbstractDefinition {
254
// Definition of a window
255
}
256
257
public interface AggregationDefinition extends AbstractDefinition {
258
// Definition of an aggregation
259
}
260
261
public interface AbstractDefinition {
262
// Base interface for all definitions
263
}
264
265
public interface SiddhiDebugger {
266
// Interface for debugging Siddhi applications
267
}
268
269
public interface ExceptionHandler<T> {
270
void handle(T object, Exception exception);
271
}
272
273
public interface ExceptionListener {
274
void exceptionThrown(Exception exception);
275
}
276
277
public interface DataSource {
278
// Data source interface for external data
279
}
280
```