Skip to content

Commit

Permalink
Remove some unused code in sdk module
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanwenjun committed Nov 18, 2021
1 parent 90e7864 commit e8a8762
Show file tree
Hide file tree
Showing 27 changed files with 597 additions and 543 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.apache.eventmesh.common;

import java.io.Serializable;

/**
* <ul>
* <li>Tcp transport object{@link org.apache.eventmesh.common.protocol.tcp.Package}</li>
* <li>Http transport object{@link org.apache.eventmesh.common.command.HttpCommand}</li>
* </ul>
*/
public interface ProtocolTransportObject extends Serializable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package org.apache.eventmesh.common.command;

import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.ProtocolTransportObject;
import org.apache.eventmesh.common.protocol.http.body.BaseResponseBody;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode;
import org.apache.eventmesh.common.protocol.http.header.BaseResponseHeader;
import org.apache.eventmesh.common.protocol.http.header.Header;
import org.apache.eventmesh.common.utils.JsonUtils;
Expand All @@ -38,9 +40,9 @@
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;

public class HttpCommand {
public class HttpCommand implements ProtocolTransportObject {

private static AtomicLong requestId = new AtomicLong(0);
private static final AtomicLong requestId = new AtomicLong(0);

private long opaque;

Expand Down Expand Up @@ -90,7 +92,7 @@ public HttpCommand createHttpCommandResponse(Header header,
return response;
}

public HttpCommand createHttpCommandResponse(Integer retCode, String retMsg) {
public HttpCommand createHttpCommandResponse(EventMeshRetCode eventMeshRetCode) {
if (StringUtils.isBlank(requestCode)) {
return null;
}
Expand All @@ -101,8 +103,8 @@ public HttpCommand createHttpCommandResponse(Integer retCode, String retMsg) {
baseResponseHeader.setCode(requestCode);
response.setHeader(baseResponseHeader);
BaseResponseBody baseResponseBody = new BaseResponseBody();
baseResponseBody.setRetCode(retCode);
baseResponseBody.setRetMsg(retMsg);
baseResponseBody.setRetCode(eventMeshRetCode.getRetCode());
baseResponseBody.setRetMsg(eventMeshRetCode.getErrMsg());
response.setBody(baseResponseBody);
response.setCmdType(CmdType.RES);
response.setResTime(System.currentTimeMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package org.apache.eventmesh.common.protocol.tcp;

public class Package {
import org.apache.eventmesh.common.ProtocolTransportObject;

public class Package implements ProtocolTransportObject {

private Header header;
private Object body;
Expand Down
6 changes: 6 additions & 0 deletions eventmesh-protocol-plugin/eventmesh-protocol-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ dependencies {

testImplementation "io.cloudevents:cloudevents-core"
testImplementation "junit:junit"

compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'

testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.eventmesh.protocol.api;

import org.apache.eventmesh.common.ProtocolTransportObject;
import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;
import org.apache.eventmesh.spi.EventMeshExtensionType;
Expand All @@ -35,7 +36,7 @@
* @since 1.3.0
*/
@EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.PROTOCOL)
public interface ProtocolAdaptor<T> {
public interface ProtocolAdaptor<T extends ProtocolTransportObject> {

/**
* transform protocol to {@link CloudEvent}.
Expand All @@ -59,7 +60,7 @@ public interface ProtocolAdaptor<T> {
* @param cloudEvent clout event
* @return target protocol
*/
Object fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException;
ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException;

/**
* Get protocol type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@

package org.apache.eventmesh.protocol.api;

import org.apache.eventmesh.common.ProtocolTransportObject;
import org.apache.eventmesh.spi.EventMeshExtensionFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import lombok.experimental.UtilityClass;

/**
* A factory to get Protocol plugin instance.
*
* @since 1.3.0
*/
public enum ProtocolPluginFactory {
;
@UtilityClass
public class ProtocolPluginFactory {

private static final Map<String, ProtocolAdaptor> PROTOCOL_ADAPTOR_MAP =
private static final Map<String, ProtocolAdaptor<ProtocolTransportObject>> PROTOCOL_ADAPTOR_MAP =
new ConcurrentHashMap<>(16);

/**
Expand All @@ -40,8 +43,9 @@ public enum ProtocolPluginFactory {
* @return protocol adaptor
* @throws IllegalArgumentException if protocol not found
*/
public static ProtocolAdaptor getProtocolAdaptor(String protocolType) {
ProtocolAdaptor protocolAdaptor = PROTOCOL_ADAPTOR_MAP.computeIfAbsent(
@SuppressWarnings("unchecked")
public static ProtocolAdaptor<ProtocolTransportObject> getProtocolAdaptor(String protocolType) {
ProtocolAdaptor<ProtocolTransportObject> protocolAdaptor = PROTOCOL_ADAPTOR_MAP.computeIfAbsent(
protocolType,
(type) -> EventMeshExtensionFactory.getExtension(ProtocolAdaptor.class, type)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import io.cloudevents.CloudEvent;
import org.apache.commons.lang3.StringUtils;
import org.apache.eventmesh.common.Constants;
import org.apache.eventmesh.common.ProtocolTransportObject;
import org.apache.eventmesh.common.command.HttpCommand;
import org.apache.eventmesh.common.protocol.http.body.Body;
import org.apache.eventmesh.common.protocol.http.common.RequestCode;
import org.apache.eventmesh.common.protocol.tcp.Header;
import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;

import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException;
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageBatchProtocolResolver;
import org.apache.eventmesh.protocol.cloudevents.resolver.http.SendMessageBatchV2ProtocolResolver;
Expand All @@ -41,10 +41,11 @@
*
* @since 1.3.0
*/
public class CloudEventsProtocolAdaptor<T> implements ProtocolAdaptor<T> {
public class CloudEventsProtocolAdaptor<T extends ProtocolTransportObject>
implements ProtocolAdaptor<ProtocolTransportObject> {

@Override
public CloudEvent toCloudEvent(T cloudEvent) throws ProtocolHandleException {
public CloudEvent toCloudEvent(ProtocolTransportObject cloudEvent) throws ProtocolHandleException {

if (cloudEvent instanceof Package) {
Header header = ((Package) cloudEvent).getHeader();
Expand Down Expand Up @@ -84,15 +85,18 @@ private CloudEvent deserializeHttpProtocol(String requestCode, org.apache.eventm
}

@Override
public List<CloudEvent> toBatchCloudEvent(T protocol) throws ProtocolHandleException {
public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol)
throws ProtocolHandleException {
return null;
}

@Override
public Object fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws ProtocolHandleException {
String protocolDesc = cloudEvent.getExtension(Constants.PROTOCOL_DESC).toString();
if (StringUtils.equals("http", protocolDesc)) {
return new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8);
// todo: return command, set cloudEvent.getData() to content?
return null;
// return new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8);
} else if (StringUtils.equals("tcp", protocolDesc)) {
Package pkg = new Package();
pkg.setBody(cloudEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.eventmesh.protocol.openmessage;

import org.apache.eventmesh.common.ProtocolTransportObject;
import org.apache.eventmesh.common.protocol.tcp.Package;
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;

Expand All @@ -33,20 +34,20 @@
*
* @since 1.3.0
*/
public class OpenMessageProtocolAdaptor<T> implements ProtocolAdaptor<T> {
public class OpenMessageProtocolAdaptor<T extends ProtocolTransportObject> implements ProtocolAdaptor<ProtocolTransportObject> {

@Override
public CloudEvent toCloudEvent(T message) {
public CloudEvent toCloudEvent(ProtocolTransportObject message) {
return null;
}

@Override
public List<CloudEvent> toBatchCloudEvent(T protocol) throws ProtocolHandleException {
public List<CloudEvent> toBatchCloudEvent(ProtocolTransportObject protocol) throws ProtocolHandleException {
return null;
}

@Override
public Object fromCloudEvent(CloudEvent cloudEvent) {
public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) {
return null;
}

Expand Down
Loading

0 comments on commit e8a8762

Please sign in to comment.