0
# Endpoint Framework
1
2
The endpoint framework provides a pluggable architecture for creating different types of gateway endpoints (REST, HiveServer2, custom) with SPI-based discovery and configuration management.
3
4
## Capabilities
5
6
### SqlGatewayEndpoint
7
8
Base interface for all gateway endpoints with lifecycle management.
9
10
```java { .api }
11
/**
12
* Base interface for gateway endpoints
13
*/
14
public interface SqlGatewayEndpoint {
15
/**
16
* Start the endpoint and begin accepting connections
17
* @throws Exception if startup fails
18
*/
19
void start() throws Exception;
20
21
/**
22
* Stop the endpoint and clean up resources
23
* @throws Exception if shutdown fails
24
*/
25
void stop() throws Exception;
26
}
27
```
28
29
### SqlGatewayEndpointFactory
30
31
Factory interface for creating endpoint instances using SPI discovery.
32
33
```java { .api }
34
/**
35
* Factory for creating SqlGatewayEndpoint instances
36
*/
37
public interface SqlGatewayEndpointFactory {
38
/**
39
* Create endpoint instance with context
40
* @param context Factory context with service and configuration
41
* @return SqlGatewayEndpoint instance
42
*/
43
SqlGatewayEndpoint createSqlGatewayEndpoint(Context context);
44
45
/**
46
* Factory context providing service and configuration access
47
*/
48
interface Context {
49
/**
50
* Get SQL Gateway service instance
51
* @return SqlGatewayService for endpoint use
52
*/
53
SqlGatewayService getSqlGatewayService();
54
55
/**
56
* Get Flink configuration
57
* @return Configuration instance
58
*/
59
Configuration getFlinkConfiguration();
60
61
/**
62
* Get endpoint-specific configuration options
63
* @return Array of ConfigOption for this endpoint type
64
*/
65
ConfigOption<?>[] getEndpointOptions();
66
}
67
}
68
```
69
70
### SqlGatewayEndpointFactoryUtils
71
72
Utility class for discovering and creating endpoints from configuration.
73
74
```java { .api }
75
/**
76
* Utilities for endpoint discovery and creation
77
*/
78
public class SqlGatewayEndpointFactoryUtils {
79
/**
80
* Create endpoints from configuration using SPI discovery
81
* @param service SqlGatewayService instance
82
* @param configuration Flink configuration
83
* @return List of created endpoints
84
* @throws Exception if endpoint creation fails
85
*/
86
public static List<SqlGatewayEndpoint> createSqlGatewayEndpoint(
87
SqlGatewayService service,
88
Configuration configuration
89
) throws Exception;
90
91
/**
92
* Create endpoint factory helper for validation
93
* @param factoryClass Factory class to validate
94
* @param configuration Configuration for validation
95
* @return FactoryHelper instance
96
*/
97
public static FactoryHelper createEndpointFactoryHelper(
98
Class<? extends SqlGatewayEndpointFactory> factoryClass,
99
Configuration configuration
100
);
101
}
102
```
103
104
## Usage Examples
105
106
### Creating Custom Endpoint
107
108
```java
109
import org.apache.flink.table.gateway.api.endpoint.SqlGatewayEndpoint;
110
import org.apache.flink.table.gateway.api.endpoint.SqlGatewayEndpointFactory;
111
112
// Custom endpoint implementation
113
public class CustomSqlGatewayEndpoint implements SqlGatewayEndpoint {
114
private final SqlGatewayService service;
115
private final Configuration config;
116
private volatile boolean running = false;
117
118
public CustomSqlGatewayEndpoint(SqlGatewayService service, Configuration config) {
119
this.service = service;
120
this.config = config;
121
}
122
123
@Override
124
public void start() throws Exception {
125
// Start custom endpoint (e.g., gRPC server, custom protocol)
126
System.out.println("Starting custom endpoint...");
127
running = true;
128
// Custom startup logic here
129
}
130
131
@Override
132
public void stop() throws Exception {
133
System.out.println("Stopping custom endpoint...");
134
running = false;
135
// Custom shutdown logic here
136
}
137
138
public boolean isRunning() {
139
return running;
140
}
141
}
142
143
// Custom endpoint factory
144
public class CustomSqlGatewayEndpointFactory implements SqlGatewayEndpointFactory {
145
146
@Override
147
public SqlGatewayEndpoint createSqlGatewayEndpoint(Context context) {
148
return new CustomSqlGatewayEndpoint(
149
context.getSqlGatewayService(),
150
context.getFlinkConfiguration()
151
);
152
}
153
}
154
```
155
156
### Using Endpoint Factory Utils
157
158
```java
159
import org.apache.flink.table.gateway.api.endpoint.SqlGatewayEndpointFactoryUtils;
160
161
// Create endpoints from configuration
162
Configuration config = new Configuration();
163
config.setString("sql-gateway.endpoint.type", "rest");
164
config.setString("sql-gateway.endpoint.rest.port", "8083");
165
166
SqlGatewayService service = new SqlGatewayServiceImpl(sessionManager);
167
168
// Create endpoints using factory utils
169
List<SqlGatewayEndpoint> endpoints = SqlGatewayEndpointFactoryUtils
170
.createSqlGatewayEndpoint(service, config);
171
172
// Start all endpoints
173
for (SqlGatewayEndpoint endpoint : endpoints) {
174
endpoint.start();
175
}
176
177
// Endpoints are now running and accepting connections
178
179
// Stop all endpoints when done
180
for (SqlGatewayEndpoint endpoint : endpoints) {
181
endpoint.stop();
182
}
183
```