-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add protocol adaptor plugin * ProtocolAdaptor deal with Package * Remove java doc check
- Loading branch information
1 parent
cc5b4c9
commit 25c2515
Showing
19 changed files
with
493 additions
and
17 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
29 changes: 29 additions & 0 deletions
29
eventmesh-protocol-plugin/eventmesh-protocol-api/build.gradle
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,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
dependencies { | ||
implementation project(":eventmesh-spi") | ||
implementation project(":eventmesh-common") | ||
|
||
implementation "io.cloudevents:cloudevents-core" | ||
|
||
testImplementation project(":eventmesh-spi") | ||
testImplementation project(":eventmesh-common") | ||
|
||
testImplementation "io.cloudevents:cloudevents-core" | ||
testImplementation "junit:junit" | ||
} |
61 changes: 61 additions & 0 deletions
61
...entmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolAdaptor.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,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.api; | ||
|
||
import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; | ||
import org.apache.eventmesh.spi.EventMeshExtensionType; | ||
import org.apache.eventmesh.spi.EventMeshSPI; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.v1.CloudEventV1; | ||
|
||
/** | ||
* Protocol transformer SPI interface, all protocol plugin should implementation. | ||
* | ||
* <p>All protocol stored in EventMesh is {@link CloudEvent}. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
@EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.PROTOCOL) | ||
public interface ProtocolAdaptor { | ||
|
||
/** | ||
* transform protocol to {@link CloudEvent}. | ||
* | ||
* @param protocol input protocol | ||
* @return cloud event | ||
*/ | ||
CloudEventV1 toCloudEventV1(Package protocol) throws ProtocolHandleException; | ||
|
||
|
||
/** | ||
* Transform {@link CloudEvent} to target protocol. | ||
* | ||
* @param cloudEvent clout event | ||
* @return target protocol | ||
*/ | ||
Package fromCloudEventV1(CloudEventV1 cloudEvent) throws ProtocolHandleException; | ||
|
||
/** | ||
* Get protocol type. | ||
* | ||
* @return protocol type, protocol type should not be null | ||
*/ | ||
String getProtocolType(); | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...h-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolPluginFactory.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,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.api; | ||
|
||
import org.apache.eventmesh.spi.EventMeshExtensionFactory; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* A factory to get Protocol plugin instance. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
public enum ProtocolPluginFactory { | ||
; | ||
|
||
private static final Map<String, ProtocolAdaptor> PROTOCOL_ADAPTOR_MAP = | ||
new ConcurrentHashMap<>(16); | ||
|
||
/** | ||
* Get protocol adaptor by name. | ||
* | ||
* @param protocolType protocol type | ||
* @return protocol adaptor | ||
* @throws IllegalArgumentException if protocol not found | ||
*/ | ||
public static ProtocolAdaptor getProtocolAdaptor(String protocolType) { | ||
ProtocolAdaptor protocolAdaptor = PROTOCOL_ADAPTOR_MAP.computeIfAbsent( | ||
protocolType, | ||
(type) -> EventMeshExtensionFactory.getExtension(ProtocolAdaptor.class, type) | ||
); | ||
if (protocolAdaptor == null) { | ||
throw new IllegalArgumentException( | ||
String.format("Cannot find the Protocol adaptor: %s", protocolType) | ||
); | ||
} | ||
return protocolAdaptor; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...pi/src/main/java/org/apache/eventmesh/protocol/api/exception/ProtocolHandleException.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,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.api.exception; | ||
|
||
/** | ||
* Protocol Handle exception, will be thrown in protocol handling. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
public class ProtocolHandleException extends Exception { | ||
|
||
public ProtocolHandleException(String message) { | ||
super(message); | ||
} | ||
|
||
public ProtocolHandleException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/build.gradle
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,25 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
dependencies { | ||
compileOnly project(":eventmesh-protocol-plugin:eventmesh-protocol-api") | ||
implementation "io.cloudevents:cloudevents-core" | ||
|
||
testImplementation project(":eventmesh-protocol-plugin:eventmesh-protocol-api") | ||
testImplementation "io.cloudevents:cloudevents-core" | ||
testImplementation "junit:junit" | ||
} |
45 changes: 45 additions & 0 deletions
45
...s/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.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,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.cloudevents; | ||
|
||
import org.apache.eventmesh.protocol.api.ProtocolAdaptor; | ||
|
||
import io.cloudevents.core.v1.CloudEventV1; | ||
|
||
/** | ||
* CloudEvents protocol adaptor, used to transform CloudEvents message to CloudEvents message. | ||
* | ||
* @since 1.3.0 | ||
*/ | ||
public class CloudEventsProtocolAdaptor implements ProtocolAdaptor { | ||
|
||
@Override | ||
public CloudEventV1 toCloudEventV1(Package cloudEvent) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Package fromCloudEventV1(CloudEventV1 cloudEvent) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getProtocolType() { | ||
return CloudEventsProtocolConstant.PROTOCOL_NAME; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolConstant.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,23 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.cloudevents; | ||
|
||
public enum CloudEventsProtocolConstant { | ||
; | ||
public static final String PROTOCOL_NAME = "cloudevents"; | ||
} |
16 changes: 16 additions & 0 deletions
16
...s/src/main/resources/META-INF/eventmesh/org.apache.eventmesh.protocol.api.ProtocolAdaptor
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,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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. | ||
|
||
cloudevents=org.apache.eventmesh.protocol.cloudevents.CloudEventsProtocolAdaptor |
38 changes: 38 additions & 0 deletions
38
...c/test/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptorTest.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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
package org.apache.eventmesh.protocol.cloudevents; | ||
|
||
import org.apache.eventmesh.protocol.api.ProtocolAdaptor; | ||
import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class CloudEventsProtocolAdaptorTest { | ||
|
||
@Test | ||
public void loadPlugin() { | ||
ProtocolAdaptor protocolAdaptor = | ||
ProtocolPluginFactory.getProtocolAdaptor(CloudEventsProtocolConstant.PROTOCOL_NAME); | ||
|
||
Assert.assertNotNull(protocolAdaptor); | ||
Assert.assertEquals( | ||
CloudEventsProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType()); | ||
Assert.assertEquals(CloudEventsProtocolAdaptor.class, protocolAdaptor.getClass()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
eventmesh-protocol-plugin/eventmesh-protocol-openmessage/build.gradle
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,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
|
||
dependencies { | ||
compileOnly project(":eventmesh-protocol-plugin:eventmesh-protocol-api") | ||
implementation "io.cloudevents:cloudevents-core" | ||
implementation "io.openmessaging:openmessaging-api" | ||
|
||
testImplementation project(":eventmesh-protocol-plugin:eventmesh-protocol-api") | ||
testImplementation "io.cloudevents:cloudevents-core" | ||
testImplementation "io.openmessaging:openmessaging-api" | ||
testImplementation "junit:junit" | ||
} |
Oops, something went wrong.