CalvinKirs
4 years ago
14 changed files with 258 additions and 22 deletions
@ -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. |
||||
*/ |
||||
|
||||
package org.apache.dolphinscheduler.remote.rpc.base; |
||||
|
||||
import java.lang.annotation.ElementType; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
import java.lang.annotation.Target; |
||||
|
||||
@Target({ElementType.TYPE}) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
public @interface RpcService { |
||||
String value() default ""; |
||||
} |
@ -0,0 +1,42 @@
|
||||
/* |
||||
* 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.dolphinscheduler.remote.rpc.common; |
||||
|
||||
public enum RequestEventType { |
||||
|
||||
HEARTBEAT((byte)1,"heartbeat"), |
||||
BUSINESS((byte)2,"business request"); |
||||
|
||||
|
||||
private Byte type; |
||||
|
||||
private String description; |
||||
|
||||
RequestEventType(Byte type, String description) { |
||||
this.type = type; |
||||
this.description = description; |
||||
} |
||||
|
||||
public Byte getType() { |
||||
return type; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc.common;/* |
||||
* 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. |
||||
*/ |
||||
|
||||
public enum ResponseEventType { |
||||
|
||||
ACK((byte) 1, "ack"), |
||||
BUSINESS_RSP((byte) 2, "business response"); |
||||
|
||||
private Byte type; |
||||
|
||||
private String description; |
||||
|
||||
ResponseEventType(Byte type, String description) { |
||||
this.type = type; |
||||
this.description = description; |
||||
} |
||||
|
||||
|
||||
public Byte getType() { |
||||
return type; |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return description; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,68 @@
|
||||
/* |
||||
* 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.dolphinscheduler.remote.rpc.config; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.IUserService; |
||||
import org.apache.dolphinscheduler.remote.rpc.base.RpcService; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.ServiceLoader; |
||||
import java.util.concurrent.atomic.AtomicBoolean; |
||||
|
||||
|
||||
import org.reflections.Reflections; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
|
||||
public class ServiceBean { |
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ServiceBean.class); |
||||
|
||||
private static Map<String, Object> serviceMap = new HashMap<>(); |
||||
|
||||
private static AtomicBoolean initialized = new AtomicBoolean(false); |
||||
|
||||
private static synchronized void init() { |
||||
Reflections f = new Reflections("org/apache/dolphinscheduler/remote/rpc"); |
||||
|
||||
|
||||
List<Class<?>> list = new ArrayList<>(f.getTypesAnnotatedWith(RpcService.class)); |
||||
list.forEach(rpcClass -> { |
||||
RpcService rpcService = rpcClass.getAnnotation(RpcService.class); |
||||
serviceMap.put(rpcService.value(), rpcClass); |
||||
}); |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
init(); |
||||
} |
||||
|
||||
public static Class getServiceClass(String className) { |
||||
if (initialized.get()) { |
||||
return (Class) serviceMap.get(className); |
||||
} else { |
||||
init(); |
||||
} |
||||
return (Class) serviceMap.get(className); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue