提交 e7f613ee 编写于 作者: P peng-yongsheng

Add the services and implements in server manager module.

上级 67ebaf3a
......@@ -18,10 +18,10 @@
package org.skywalking.apm.collector.server.grpc;
import org.skywalking.apm.collector.core.framework.Handler;
import org.skywalking.apm.collector.server.ServerHandler;
/**
* @author peng-yongsheng
*/
public interface GRPCHandler extends Handler {
public interface GRPCHandler extends ServerHandler {
}
......@@ -30,13 +30,13 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.skywalking.apm.collector.core.framework.Handler;
import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.skywalking.apm.collector.server.ServerHandler;
/**
* @author peng-yongsheng
*/
public abstract class JettyHandler extends HttpServlet implements Handler {
public abstract class JettyHandler extends HttpServlet implements ServerHandler {
public abstract String pathSpec();
......
......@@ -22,9 +22,9 @@ import java.net.InetSocketAddress;
import javax.servlet.http.HttpServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.skywalking.apm.collector.core.framework.Handler;
import org.skywalking.apm.collector.core.server.Server;
import org.skywalking.apm.collector.core.server.ServerException;
import org.skywalking.apm.collector.server.Server;
import org.skywalking.apm.collector.server.ServerException;
import org.skywalking.apm.collector.server.ServerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -65,7 +65,7 @@ public class JettyServer implements Server {
server.setHandler(servletContextHandler);
}
@Override public void addHandler(Handler handler) {
@Override public void addHandler(ServerHandler handler) {
ServletHolder servletHolder = new ServletHolder();
servletHolder.setServlet((HttpServlet)handler);
servletContextHandler.addServlet(servletHolder, ((JettyHandler)handler).pathSpec());
......
......@@ -18,7 +18,7 @@
package org.skywalking.apm.collector.server.jetty;
import org.skywalking.apm.collector.core.server.ServerException;
import org.skywalking.apm.collector.server.ServerException;
/**
* @author peng-yongsheng
......
......@@ -30,4 +30,11 @@
<artifactId>collector-grpc-manager-provider</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>collector-server-manager-define</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -22,6 +22,9 @@ import java.util.Properties;
import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.core.module.ModuleProvider;
import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
import org.skywalking.apm.collector.server.manager.ServerManagerModule;
import org.skywalking.apm.collector.server.manager.grpc.service.GRPCServerService;
import org.skywalking.apm.collector.server.manager.service.GRPCServerManagerService;
/**
* @author peng-yongsheng
......@@ -29,15 +32,15 @@ import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
public class ServerManagerModuleGRPCProvider extends ModuleProvider {
@Override public String name() {
return null;
return "Google_RPC";
}
@Override public Class<? extends Module> module() {
return null;
return ServerManagerModule.class;
}
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
this.registerServiceImplementation(GRPCServerManagerService.class, new GRPCServerService());
}
@Override public void init(Properties config) throws ServiceNotProvidedException {
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.grpc.service;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.server.Server;
import org.skywalking.apm.collector.server.grpc.GRPCServer;
import org.skywalking.apm.collector.server.manager.service.GRPCServerConfig;
import org.skywalking.apm.collector.server.manager.service.GRPCServerManagerService;
/**
* @author peng-yongsheng
*/
public class GRPCServerService implements GRPCServerManagerService {
private Map<String, GRPCServer> servers = new HashMap<>();
@Override public Server getElseCreateServer(GRPCServerConfig config) {
String id = config.getHost() + String.valueOf(config.getPort());
if (servers.containsKey(id)) {
return servers.get(id);
} else {
GRPCServer server = new GRPCServer(config.getHost(), config.getPort());
servers.put(id, server);
return server;
}
}
}
......@@ -30,4 +30,11 @@
<artifactId>collector-jetty-manager-provider</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.skywalking</groupId>
<artifactId>collector-server-manager-define</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -22,6 +22,9 @@ import java.util.Properties;
import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.core.module.ModuleProvider;
import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
import org.skywalking.apm.collector.server.manager.ServerManagerModule;
import org.skywalking.apm.collector.server.manager.jetty.service.JettyServerService;
import org.skywalking.apm.collector.server.manager.service.JettyServerManagerService;
/**
* @author peng-yongsheng
......@@ -29,15 +32,15 @@ import org.skywalking.apm.collector.core.module.ServiceNotProvidedException;
public class ServerManagerModuleJettyProvider extends ModuleProvider {
@Override public String name() {
return null;
return "Jetty";
}
@Override public Class<? extends Module> module() {
return null;
return ServerManagerModule.class;
}
@Override public void prepare(Properties config) throws ServiceNotProvidedException {
this.registerServiceImplementation(JettyServerManagerService.class, new JettyServerService());
}
@Override public void init(Properties config) throws ServiceNotProvidedException {
......
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.jetty.service;
import java.util.HashMap;
import java.util.Map;
import org.skywalking.apm.collector.server.Server;
import org.skywalking.apm.collector.server.jetty.JettyServer;
import org.skywalking.apm.collector.server.manager.service.JettyServerConfig;
import org.skywalking.apm.collector.server.manager.service.JettyServerManagerService;
/**
* @author peng-yongsheng
*/
public class JettyServerService implements JettyServerManagerService {
private Map<String, JettyServer> servers = new HashMap<>();
@Override public Server getElseCreateServer(JettyServerConfig config) {
String id = config.getHost() + String.valueOf(config.getPort());
if (servers.containsKey(id)) {
return servers.get(id);
} else {
JettyServer server = new JettyServer(config.getHost(), config.getPort(), config.getContextPath());
servers.put(id, server);
return server;
}
}
}
......@@ -19,6 +19,8 @@
package org.skywalking.apm.collector.server.manager;
import org.skywalking.apm.collector.core.module.Module;
import org.skywalking.apm.collector.server.manager.service.GRPCServerManagerService;
import org.skywalking.apm.collector.server.manager.service.JettyServerManagerService;
/**
* @author peng-yongsheng
......@@ -32,6 +34,6 @@ public class ServerManagerModule extends Module {
}
@Override public Class[] services() {
return new Class[0];
return new Class[] {GRPCServerManagerService.class, JettyServerManagerService.class};
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.service;
/**
* @author peng-yongsheng
*/
public class GRPCServerConfig extends ServerConfig {
public GRPCServerConfig(String host, int port) {
super(host, port);
}
}
......@@ -16,12 +16,10 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server;
import org.skywalking.apm.collector.core.module.ModuleDefine;
package org.skywalking.apm.collector.server.manager.service;
/**
* @author peng-yongsheng
*/
public abstract class ServerModuleDefine extends ModuleDefine {
public interface GRPCServerManagerService extends ManagerService<GRPCServerConfig> {
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.service;
/**
* @author peng-yongsheng
*/
public class JettyServerConfig extends ServerConfig {
private final String contextPath;
public JettyServerConfig(String host, int port, String contextPath) {
super(host, port);
this.contextPath = contextPath;
}
public final String getContextPath() {
return contextPath;
}
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.service;
/**
* @author peng-yongsheng
*/
public interface JettyServerManagerService extends ManagerService<JettyServerConfig> {
}
/*
* Copyright 2017, OpenSkywalking Organization All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server.manager.service;
import org.skywalking.apm.collector.core.module.Service;
import org.skywalking.apm.collector.server.Server;
/**
* @author peng-yongsheng
*/
public interface ManagerService<T extends ServerConfig> extends Service {
Server getElseCreateServer(T config);
}
......@@ -16,57 +16,25 @@
* Project repository: https://github.com/OpenSkywalking/skywalking
*/
package org.skywalking.apm.collector.server;
import java.util.LinkedList;
import java.util.List;
import org.skywalking.apm.collector.core.util.CollectionUtils;
import org.skywalking.apm.collector.core.util.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.skywalking.apm.collector.server.manager.service;
/**
* @author peng-yongsheng
*/
public class ServerHolder {
private final Logger logger = LoggerFactory.getLogger(ServerHolder.class);
private List<Server> servers;
public ServerHolder() {
servers = new LinkedList<>();
}
public void holdServer(Server newServer, List<ServerHandler> handlers) throws ServerException {
if (ObjectUtils.isEmpty(newServer) || CollectionUtils.isEmpty(handlers)) {
return;
}
public abstract class ServerConfig {
private final String host;
private final int port;
boolean isNewServer = true;
for (Server server : servers) {
if (server.hostPort().equals(newServer.hostPort()) && server.serverClassify().equals(newServer.serverClassify())) {
isNewServer = false;
addHandler(handlers, server);
}
}
if (isNewServer) {
newServer.initialize();
servers.add(newServer);
addHandler(handlers, newServer);
}
public ServerConfig(String host, int port) {
this.host = host;
this.port = port;
}
private void addHandler(List<ServerHandler> handlers, Server server) {
if (CollectionUtils.isNotEmpty(handlers)) {
handlers.forEach(handler -> {
server.addHandler(handler);
logger.debug("add handler into server: {}, handler name: {}", server.hostPort(), handler.getClass().getName());
});
}
public final String getHost() {
return host;
}
public List<Server> getServers() {
return servers;
public final int getPort() {
return port;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册