-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb71ba8
commit 11bd024
Showing
32 changed files
with
749 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,6 @@ public interface EmbeddedServer { | |
* @return port number | ||
*/ | ||
int getPort(); | ||
|
||
int getWebPort(); | ||
} |
5 changes: 5 additions & 0 deletions
5
java/timebase/api/src/main/java/com/epam/deltix/util/vsocket/DBConnectionAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.epam.deltix.util.vsocket; | ||
|
||
public interface DBConnectionAcceptor { | ||
boolean accept(String clientId); | ||
} |
13 changes: 13 additions & 0 deletions
13
java/timebase/api/src/main/java/com/epam/deltix/util/vsocket/DefaultConnectionAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.epam.deltix.util.vsocket; | ||
|
||
public class DefaultConnectionAcceptor implements DBConnectionAcceptor { | ||
public static final DefaultConnectionAcceptor INSTANCE = new DefaultConnectionAcceptor(); | ||
|
||
private DefaultConnectionAcceptor() { | ||
} | ||
|
||
@Override | ||
public boolean accept(String clientId) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
java/timebase/commons/src/main/java/com/epam/deltix/qsrv/comm/cat/SocketServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.epam.deltix.qsrv.comm.cat; | ||
|
||
import com.epam.deltix.util.io.IOUtil; | ||
import com.epam.deltix.util.lang.Disposable; | ||
import com.epam.deltix.util.tomcat.ConnectionHandler; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.InetAddress; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.net.SocketException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class SocketServer extends Thread implements Disposable { | ||
|
||
public static final Logger LOGGER = Logger.getLogger ("deltix.tickdb.server"); | ||
|
||
private final ConnectionHandler connectionHandler; | ||
private final ServerSocket serverSocket; | ||
private final ExecutorService executor = Executors.newFixedThreadPool(4); | ||
private volatile boolean running; | ||
|
||
public SocketServer(ConnectionHandler connectionHandler) throws IOException { | ||
this(0, connectionHandler); | ||
} | ||
|
||
public SocketServer(int port, ConnectionHandler connectionHandler) throws IOException { | ||
this(port, null, connectionHandler); | ||
} | ||
|
||
public SocketServer(int port, InetAddress address, ConnectionHandler connectionHandler) throws IOException { | ||
this(new ServerSocket(port, 0, address), connectionHandler); | ||
} | ||
|
||
public SocketServer(ServerSocket serverSocket, ConnectionHandler connectionHandler) { | ||
super("VSServer on " + serverSocket); | ||
|
||
this.serverSocket = serverSocket; | ||
this.connectionHandler = connectionHandler; | ||
} | ||
|
||
public int getLocalPort() { | ||
return (serverSocket.getLocalPort()); | ||
} | ||
|
||
public int getSoTimeout() throws IOException { | ||
return serverSocket.getSoTimeout(); | ||
} | ||
|
||
public void setSoTimeout(int readTimeout) throws SocketException { | ||
serverSocket.setSoTimeout(readTimeout); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
running = true; | ||
|
||
LOGGER.log(Level.INFO, "Listening connections on port: " + serverSocket.getLocalPort()); | ||
|
||
while (running) { | ||
try { | ||
final Socket s = serverSocket.accept(); | ||
|
||
executor.execute(() -> { | ||
try { | ||
BufferedInputStream bis = new BufferedInputStream(s.getInputStream()); | ||
OutputStream os = s.getOutputStream(); | ||
if (!connectionHandler.handleConnection(s, bis, os)) { | ||
s.close(); | ||
} | ||
} catch (Throwable t) { | ||
IOUtil.close(s); | ||
LOGGER.log( | ||
Level.SEVERE, | ||
"Exception while handling handshake", | ||
t | ||
); | ||
} | ||
}); | ||
} catch (IOException iox) { | ||
if (!serverSocket.isClosed()) | ||
LOGGER.log( | ||
Level.SEVERE, | ||
"Exception while accepting connections", | ||
iox | ||
); | ||
} | ||
} | ||
|
||
if (!serverSocket.isClosed()) | ||
IOUtil.close(serverSocket); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
running = false; | ||
IOUtil.close(serverSocket); | ||
executor.shutdownNow(); | ||
interrupt(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.