CalvinKirs
4 years ago
33 changed files with 301 additions and 274 deletions
@ -1,12 +0,0 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.common.RpcResponse; |
||||
import org.apache.dolphinscheduler.remote.rpc.common.RpcRequest; |
||||
|
||||
/** |
||||
* Invoker |
||||
*/ |
||||
public interface Invoker { |
||||
|
||||
RpcResponse invoke(RpcRequest req) throws Throwable; |
||||
} |
@ -1,15 +0,0 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.config.NettyServerConfig; |
||||
import org.apache.dolphinscheduler.remote.rpc.remote.NettyServer; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-20 14:54 |
||||
*/ |
||||
public class MainServerTest { |
||||
|
||||
public static void main(String[] args) { |
||||
NettyServer nettyServer = new NettyServer(new NettyServerConfig()); |
||||
} |
||||
} |
@ -1,39 +0,0 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.config.NettyServerConfig; |
||||
import org.apache.dolphinscheduler.remote.rpc.client.IRpcClient; |
||||
import org.apache.dolphinscheduler.remote.rpc.client.RpcClient; |
||||
import org.apache.dolphinscheduler.remote.rpc.remote.NettyServer; |
||||
import org.apache.dolphinscheduler.remote.utils.Host; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-11 21:06 |
||||
*/ |
||||
public class MainTest { |
||||
|
||||
public static void main(String[] args) throws Exception { |
||||
|
||||
|
||||
// NettyServer nettyServer = new NettyServer(new NettyServerConfig());
|
||||
|
||||
// NettyClient nettyClient=new NettyClient(new NettyClientConfig());
|
||||
|
||||
Host host = new Host("127.0.0.1", 12636); |
||||
|
||||
IRpcClient rpcClient = new RpcClient(); |
||||
IUserService userService = rpcClient.create(IUserService.class, host); |
||||
boolean result = userService.say("calvin"); |
||||
System.out.println("异步回掉成功" + result); |
||||
|
||||
System.out.println(userService.hi(10)); |
||||
System.out.println(userService.hi(188888888)); |
||||
|
||||
IUserService user = rpcClient.create(IUserService.class, host); |
||||
System.out.println(user.hi(99999)); |
||||
System.out.println(user.hi(998888888)); |
||||
|
||||
System.out.println(IUserService.class.getSimpleName()); |
||||
System.out.println(UserService.class.getSimpleName()); |
||||
} |
||||
} |
@ -1,15 +0,0 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.common.AbstractRpcCallBack; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-15 07:32 |
||||
*/ |
||||
public class UserCallback extends AbstractRpcCallBack { |
||||
@Override |
||||
public void run(Object object) { |
||||
Boolean msg= (Boolean) object; |
||||
System.out.println("我是异步回调handle Kris"+msg); |
||||
} |
||||
} |
@ -1,23 +0,0 @@
|
||||
package org.apache.dolphinscheduler.remote.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.rpc.base.Rpc; |
||||
import org.apache.dolphinscheduler.remote.rpc.base.RpcService; |
||||
|
||||
/** |
||||
* @author jiangli |
||||
* @date 2021-01-11 21:05 |
||||
*/ |
||||
@RpcService("IUserService") |
||||
public class UserService implements IUserService{ |
||||
|
||||
@Rpc(async = true, serviceCallback = UserCallback.class, retries = 9999) |
||||
@Override |
||||
public Boolean say(String s) { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public String hi(int num) { |
||||
return "this world has " + num + "sun"; |
||||
} |
||||
} |
@ -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.dolphinscheduler.rpc.common; |
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue; |
||||
import java.util.concurrent.ExecutorService; |
||||
import java.util.concurrent.ThreadPoolExecutor; |
||||
import java.util.concurrent.ThreadPoolExecutor.DiscardPolicy; |
||||
import java.util.concurrent.TimeUnit; |
||||
|
||||
public enum ThreadPoolManager { |
||||
|
||||
INSTANCE; |
||||
|
||||
ExecutorService executorService; |
||||
|
||||
ThreadPoolManager() { |
||||
int SIZE_WORK_QUEUE = 200; |
||||
long KEEP_ALIVE_TIME = 60; |
||||
int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors() * 2; |
||||
int MAXI_MUM_POOL_SIZE = CORE_POOL_SIZE * 4; |
||||
executorService = new ThreadPoolExecutor(CORE_POOL_SIZE, MAXI_MUM_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, |
||||
new ArrayBlockingQueue<>(SIZE_WORK_QUEUE), |
||||
new DiscardPolicy()); |
||||
} |
||||
|
||||
public void addExecuteTask(Runnable task) { |
||||
executorService.submit(task); |
||||
} |
||||
} |
@ -0,0 +1,63 @@
|
||||
/* |
||||
* 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.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.remote.config.NettyServerConfig; |
||||
import org.apache.dolphinscheduler.remote.utils.Host; |
||||
import org.apache.dolphinscheduler.rpc.client.IRpcClient; |
||||
import org.apache.dolphinscheduler.rpc.client.RpcClient; |
||||
import org.apache.dolphinscheduler.rpc.remote.NettyClient; |
||||
import org.apache.dolphinscheduler.rpc.remote.NettyServer; |
||||
|
||||
import org.junit.After; |
||||
import org.junit.Assert; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class RpcTest { |
||||
private NettyServer nettyServer; |
||||
|
||||
private IUserService userService; |
||||
|
||||
private Host host; |
||||
|
||||
@Before |
||||
public void before() throws Exception { |
||||
nettyServer = new NettyServer(new NettyServerConfig()); |
||||
IRpcClient rpcClient = new RpcClient(); |
||||
host = new Host("127.0.0.1", 12346); |
||||
userService = rpcClient.create(IUserService.class, host); |
||||
|
||||
} |
||||
|
||||
@Test |
||||
public void sendTest() { |
||||
Integer result = userService.hi(3); |
||||
Assert.assertSame(4, result); |
||||
result = userService.hi(4); |
||||
Assert.assertSame(5, result); |
||||
userService.say("sync"); |
||||
} |
||||
|
||||
@After |
||||
public void after() { |
||||
NettyClient.getInstance().close(); |
||||
nettyServer.close(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
/* |
||||
* 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.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.rpc.common.AbstractRpcCallBack; |
||||
|
||||
/** |
||||
* UserCallback |
||||
*/ |
||||
public class UserCallback extends AbstractRpcCallBack { |
||||
@Override |
||||
public void run(Object object) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
package org.apache.dolphinscheduler.rpc; |
||||
|
||||
import org.apache.dolphinscheduler.rpc.base.RpcService; |
||||
|
||||
/** |
||||
* UserService |
||||
*/ |
||||
@RpcService("IUserService") |
||||
public class UserService implements IUserService{ |
||||
|
||||
@Override |
||||
public Boolean say(String s) { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public Integer hi(int num) { |
||||
return ++num; |
||||
} |
||||
} |
Loading…
Reference in new issue