Skip to content

Commit

Permalink
1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
noear committed May 26, 2022
1 parent d7340e2 commit 77dad30
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,20 @@
import org.noear.solon.Solon;
import org.noear.solon.SolonApp;
import org.noear.solon.Utils;
import org.noear.solon.boot.ServerLifecycle;
import org.noear.solon.boot.jetty.websocket._SessionManagerImpl;
import org.noear.solon.core.AopContext;
import org.noear.solon.core.event.EventBus;
import org.noear.solon.core.Plugin;
import org.noear.solon.socketd.SessionManager;

import java.io.IOException;

class PluginJetty extends PluginJettyBase implements Plugin {
class JettyServer extends JettyServerBase implements ServerLifecycle {
protected Server _server = null;
private int port;
private String host;

public PluginJetty(int port, String host) {
this.port = port;
this.host = host;
}

@Override
public void start(AopContext context) {
try {
setup(Solon.app(), context);
_server.start();
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
public void start(String host, int port) throws Throwable {
setup(Solon.app(), host, port);
_server.start();
}

@Override
Expand All @@ -43,7 +29,7 @@ public void stop() throws Throwable {
}
}

protected void setup(SolonApp app, AopContext context) throws IOException {
protected void setup(SolonApp app, String host, int port) throws IOException {
Class<?> wsClz = Utils.loadClass("org.eclipse.jetty.websocket.server.WebSocketHandler");

_server = new Server();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
import java.net.URLClassLoader;
import java.util.Properties;

class PluginJettyJsp extends PluginJetty {

public PluginJettyJsp(int port, String host) {
super(port, host);
}
class JettyServerAddJsp extends JettyServer {

/**
* 获取Server Handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.net.MalformedURLException;
import java.net.URL;

class PluginJettyBase {
class JettyServerBase {
/**
* 创建连接器(支持https)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

public final class XPluginImp implements Plugin {
private static Signal _signal;
public static Signal signal(){

public static Signal signal() {
return _signal;
}

private PluginJetty _server = null;
private JettyServer _server = null;


public static String solon_boot_ver(){
public static String solon_boot_ver() {
return "jetty 9.4/" + Solon.cfg().version();
}

Expand All @@ -39,16 +40,25 @@ public void start(AopContext context) {
String.valueOf(ServerProps.request_maxBodySize));
}

context.beanBuilderAdd(WebFilter.class,(clz, bw, ano)->{});
context.beanBuilderAdd(WebServlet.class,(clz, bw, ano)->{});
context.beanBuilderAdd(WebListener.class,(clz, bw, ano)->{});
context.beanBuilderAdd(WebFilter.class, (clz, bw, ano) -> {
});
context.beanBuilderAdd(WebServlet.class, (clz, bw, ano) -> {
});
context.beanBuilderAdd(WebListener.class, (clz, bw, ano) -> {
});

context.beanOnloaded((ctx) -> {
start0(Solon.app(), context);
try {
start0(Solon.app());
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
});
}

private void start0(SolonApp app, AopContext context) {
private void start0(SolonApp app) throws Throwable{
Class<?> jspClz = Utils.loadClass("org.eclipse.jetty.jsp.JettyJspServlet");


Expand All @@ -64,15 +74,15 @@ private void start0(SolonApp app, AopContext context) {


if (jspClz == null) {
_server = new PluginJetty(_port, _host);
_server = new JettyServer();
} else {
_server = new PluginJettyJsp(_port, _host);
_server = new JettyServerAddJsp();
}

long time_start = System.currentTimeMillis();
PrintUtil.info("Server:main: Jetty 9.4(jetty)");

_server.start(context);
_server.start(_host, _port);
_signal = new SignalSim(_name, _port, "http", SignalType.HTTP);

app.signalAdd(_signal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ public void start(AopContext context) {
}

context.beanOnloaded((ctx) -> {
start0(Solon.app());
try {
start0(Solon.app());
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
});
}

private void start0(SolonApp app) {
private void start0(SolonApp app) throws Throwable{
_server = new HTTPServer();

String _name = app.cfg().get(ServerConstants.SERVER_HTTP_NAME);
Expand All @@ -76,52 +82,45 @@ private void start0(SolonApp app) {
HTTPServer.MAX_BODY_SIZE = ServerProps.request_maxBodySize;
}

try {

JlHttpContextHandler _handler = new JlHttpContextHandler();
JlHttpContextHandler _handler = new JlHttpContextHandler();


if (System.getProperty(ServerConstants.SSL_KEYSTORE) != null) { // enable SSL if configured
_server.setServerSocketFactory(SslContextFactory.createSslContext().getServerSocketFactory());
}
if (System.getProperty(ServerConstants.SSL_KEYSTORE) != null) { // enable SSL if configured
_server.setServerSocketFactory(SslContextFactory.createSslContext().getServerSocketFactory());
}

HTTPServer.VirtualHost host = _server.getVirtualHost(null);
HTTPServer.VirtualHost host = _server.getVirtualHost(null);


host.setDirectoryIndex(null);
host.setDirectoryIndex(null);

host.addContext("/", _handler,
MethodType.HEAD.name,
MethodType.GET.name,
MethodType.POST.name,
MethodType.PUT.name,
MethodType.DELETE.name,
MethodType.PATCH.name,
MethodType.OPTIONS.name);
host.addContext("/", _handler,
MethodType.HEAD.name,
MethodType.GET.name,
MethodType.POST.name,
MethodType.PUT.name,
MethodType.DELETE.name,
MethodType.PATCH.name,
MethodType.OPTIONS.name);

PrintUtil.info("Server:main: JlHttpServer 2.6(jlhttp)");
PrintUtil.info("Server:main: JlHttpServer 2.6(jlhttp)");


_server.setExecutor(Executors.newCachedThreadPool(new NamedThreadFactory("jlhttp-")));
_server.setPort(_port);
if (Utils.isNotEmpty(_host)) {
_server.setHost(_host);
}
_server.start();
_server.setExecutor(Executors.newCachedThreadPool(new NamedThreadFactory("jlhttp-")));
_server.setPort(_port);
if (Utils.isNotEmpty(_host)) {
_server.setHost(_host);
}
_server.start();

_signal = new SignalSim(_name, _port, "http", SignalType.HTTP);
_signal = new SignalSim(_name, _port, "http", SignalType.HTTP);

app.signalAdd(_signal);
app.signalAdd(_signal);

long time_end = System.currentTimeMillis();
long time_end = System.currentTimeMillis();

PrintUtil.info("Connector:main: jlhttp: Started ServerConnector@{HTTP/1.1,[http/1.1]}{http://localhost:" + _port + "}");
PrintUtil.info("Server:main: jlhttp: Started @" + (time_end - time_start) + "ms");
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
PrintUtil.info("Connector:main: jlhttp: Started ServerConnector@{HTTP/1.1,[http/1.1]}{http://localhost:" + _port + "}");
PrintUtil.info("Server:main: jlhttp: Started @" + (time_end - time_start) + "ms");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ public void start(AopContext context) {
}

context.beanOnloaded((ctx) -> {
start0(Solon.app());
try {
start0(Solon.app());
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
});
}

private void start0(SolonApp app) {
private void start0(SolonApp app) throws Throwable {
String _name = app.cfg().get(ServerConstants.SERVER_HTTP_NAME);
int _port = app.cfg().getInt(ServerConstants.SERVER_HTTP_PORT, 0);
String _host = app.cfg().get(ServerConstants.SERVER_HTTP_HOST, null);
Expand Down Expand Up @@ -88,33 +94,26 @@ private void start0(SolonApp app) {

PrintUtil.info("Server:main: SmartHttpServer 1.1(smarthttp)");

try {

_server.setPort(_port);

_server.start();
_server.setPort(_port);
_server.start();

_signal = new SignalSim(_name, _port, "http", SignalType.HTTP);
_signal = new SignalSim(_name, _port, "http", SignalType.HTTP);

app.signalAdd(_signal);
app.signalAdd(_signal);

app.before(-9, new FormContentFilter());
app.before(-9, new FormContentFilter());

long time_end = System.currentTimeMillis();
long time_end = System.currentTimeMillis();

String connectorInfo = "solon.connector:main: smarthttp: Started ServerConnector@{HTTP/1.1,[http/1.1]";
if (app.enableWebSocket()) {
PrintUtil.info(connectorInfo + "[WebSocket]}{0.0.0.0:" + _port + "}");
}
String connectorInfo = "solon.connector:main: smarthttp: Started ServerConnector@{HTTP/1.1,[http/1.1]";
if (app.enableWebSocket()) {
PrintUtil.info(connectorInfo + "[WebSocket]}{0.0.0.0:" + _port + "}");
}

PrintUtil.info(connectorInfo + "}{http://localhost:" + _port + "}");
PrintUtil.info(connectorInfo + "}{http://localhost:" + _port + "}");

PrintUtil.info("Server:main: smarthttp: Started @" + (time_end - time_start) + "ms");
} catch (RuntimeException e) {
throw e;
} catch (Throwable e) {
throw new IllegalStateException(e);
}
PrintUtil.info("Server:main: smarthttp: Started @" + (time_end - time_start) + "ms");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.noear.solon.boot.socketd.jdksocket;

import org.noear.solon.Solon;
import org.noear.solon.Utils;
import org.noear.solon.boot.ServerLifecycle;
import org.noear.solon.core.message.Message;
import org.noear.solon.core.message.Session;
import org.noear.solon.core.util.PrintUtil;
Expand All @@ -9,27 +11,25 @@
import org.noear.solon.socketd.client.jdksocket.BioSocketSession;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

class BioServer {
class BioServer implements ServerLifecycle {
private ServerSocket server;
private ExecutorService pool = Executors.newCachedThreadPool(new NamedThreadFactory("jdksocket-"));

public void start(int port) {
new Thread(() -> {
try {
start0(port);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}).start();
}
private void start0(String host, int port) throws IOException {
if (Utils.isEmpty(host)) {
server = new ServerSocket(port);
} else {
InetAddress inetAddress = Inet4Address.getByName(host);
server = new ServerSocket(port, 50, inetAddress);
}

private void start0(int port) throws IOException {
server = new ServerSocket(port);

PrintUtil.info("Server started, waiting for customer connection...");

Expand Down Expand Up @@ -67,6 +67,18 @@ private void start0(int port) throws IOException {
}
}

@Override
public void start(String host, int port) throws Throwable {
new Thread(() -> {
try {
start0(host, port);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}).start();
}

@Override
public void stop() {
if (server.isClosed()) {
return;
Expand Down
Loading

0 comments on commit 77dad30

Please sign in to comment.