From 1e94d7fede53840788ba397461aaebab60795b7a Mon Sep 17 00:00:00 2001 From: "likuo011@deppon.com" Date: Sun, 20 Aug 2023 19:50:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=205.0.8=20=E9=A2=84=E5=8F=91=E5=8F=91?= =?UTF-8?q?=E5=B8=83=20feat:=20=E5=87=86=E5=A4=87=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=89=88=E6=9C=AC=E8=BF=AD=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 + mybatis-idea-plugin/build.gradle | 6 +- .../java/com/plugins/mybaitslog/PerRun.java | 10 +- .../console/MyBatisLogToolWindow.java | 4 +- .../plugins/mybaitslog/gui/FilterSetting.form | 4 +- .../com/plugins/mybaitslog/rmi/RmiServer.java | 87 --------- .../plugins/mybaitslog/unix/UnixServer.java | 76 ++++++++ .../src/main/resources/META-INF/plugin.xml | 2 +- mybatis-plugin/build.gradle | 6 +- .../linkkou/mybatis/log/LogInterceptor.java | 3 +- .../linkkou/mybatis/log/MyBatisLogRmi.java | 10 - .../com/linkkou/mybatis/log/PrintlnLog.java | 67 +++++++ .../java/com/linkkou/mybatis/log/RmiLog.java | 35 ---- .../sharedmemory/MyBatisLogRmi.java | 10 - .../sharedmemory/MyBatisLogRmi2.java | 10 - .../mybatislog/sharedmemory/index.java | 179 ------------------ 16 files changed, 159 insertions(+), 352 deletions(-) delete mode 100644 mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/rmi/RmiServer.java create mode 100644 mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/unix/UnixServer.java delete mode 100644 mybatis-plugin/src/main/java/com/linkkou/mybatis/log/MyBatisLogRmi.java create mode 100644 mybatis-plugin/src/main/java/com/linkkou/mybatis/log/PrintlnLog.java delete mode 100644 mybatis-plugin/src/main/java/com/linkkou/mybatis/log/RmiLog.java delete mode 100644 mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi.java delete mode 100644 mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi2.java delete mode 100644 mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/index.java diff --git a/README.md b/README.md index 7bcd930..57acc4d 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ IDEA --> Setting --> Plugins --> 搜索 MyBatis Log EasyPlus +#### 2023.08.20 -> 最后一个支持《IDEA 2021.1》的版本,感谢各位社区伙伴的测试反馈,现已修复若干个已知问题,装备下一个版本大迭代 + #### 2023.05.28 -> 对额外的扩展插件进行支持 #### 2023.05.22 -> 《IDEA 2021.1 以上》感谢各位社区伙伴的测试反馈,现已修复若干个已知问题 diff --git a/mybatis-idea-plugin/build.gradle b/mybatis-idea-plugin/build.gradle index c083769..95ba70f 100644 --- a/mybatis-idea-plugin/build.gradle +++ b/mybatis-idea-plugin/build.gradle @@ -35,7 +35,7 @@ allprojects { } group 'com.plugins.mybaitslog.idea.plugin' -version '5.0.8.1' +version '5.0.8.2' dependencies { implementation project(path: ':mybatis-plugin') @@ -50,8 +50,8 @@ dependencies { /*测试关闭*/ java { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" + sourceCompatibility = "8" + targetCompatibility = "8" } /*https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html#intellij-platform-based-products-of-recent-ide-versions*/ diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PerRun.java b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PerRun.java index d0060ec..c5a0e81 100644 --- a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PerRun.java +++ b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/PerRun.java @@ -6,17 +6,11 @@ import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.configurations.RunProfile; import com.intellij.execution.runners.JavaProgramPatcher; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.StoragePathMacros; -import com.intellij.openapi.module.ModuleManager; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.projectRoots.JavaSdk; import com.intellij.openapi.projectRoots.JavaSdkVersion; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.diagnostic.Logger; -import com.plugins.mybaitslog.rmi.RmiServer; -import org.jetbrains.annotations.NotNull; +import com.plugins.mybaitslog.unix.UnixServer; import java.util.*; @@ -44,7 +38,7 @@ public void patchJavaParameters(Executor executor, RunProfile configuration, Jav String id = null; if (configuration instanceof RunConfiguration) { final RunConfiguration runConfiguration = (RunConfiguration) configuration; - id = RmiServer.getId(runConfiguration.getProject()); + id = UnixServer.getId(runConfiguration.getProject()); } // Sdk jdk = javaParameters.getJdk(); diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/console/MyBatisLogToolWindow.java b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/console/MyBatisLogToolWindow.java index 726c6b1..849a930 100644 --- a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/console/MyBatisLogToolWindow.java +++ b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/console/MyBatisLogToolWindow.java @@ -7,7 +7,7 @@ import com.intellij.ui.content.ContentFactory; import com.plugins.mybaitslog.VersionControl; import com.plugins.mybaitslog.icons.Icons; -import com.plugins.mybaitslog.rmi.RmiServer; +import com.plugins.mybaitslog.unix.UnixServer; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -24,7 +24,7 @@ public class MyBatisLogToolWindow implements ToolWindowFactory { @Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { - RmiServer.boot(project); + UnixServer.boot(project); ConsolePanel consolePanel = new ConsolePanel(); final JComponent jComponent = consolePanel.getConsolePanel(project); final ContentFactory contentFactory = VersionControl.getContentFactory(); diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/gui/FilterSetting.form b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/gui/FilterSetting.form index c87341f..6c2db75 100644 --- a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/gui/FilterSetting.form +++ b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/gui/FilterSetting.form @@ -344,7 +344,7 @@ - + @@ -360,7 +360,7 @@ - + diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/rmi/RmiServer.java b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/rmi/RmiServer.java deleted file mode 100644 index 9d7f841..0000000 --- a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/rmi/RmiServer.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.plugins.mybaitslog.rmi; - -import com.intellij.openapi.project.Project; -import com.linkkou.mybatis.log.MyBatisLogRmi; -import com.plugins.mybaitslog.Config; -import com.plugins.mybaitslog.console.PrintlnUtil; -import org.jetbrains.annotations.NotNull; - -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.rmi.server.UnicastRemoteObject; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; - -/** - * A RmiServer Class - * - * @author lk - * @version 1.0 - *

date: 2023/5/12 19:20

- */ -public class RmiServer { - - public static class ServerOperation extends UnicastRemoteObject implements MyBatisLogRmi { - - private Project project; - - private static final long serialVersionUID = 1L; - - protected ServerOperation(@NotNull Project project) throws RemoteException { - super(); - this.project = project; - } - - @Override - public String log(String name) throws RemoteException { - PrintlnUtil.prints(project, name); - return "success"; - } - - } - - public static Map RMISERVERID = new ConcurrentHashMap(); - - public static String getId(@NotNull Project project) { - return RMISERVERID.get(project); - } - - public static void boot(@NotNull Project project) { - final boolean runRmi = Config.Idea.getRunRmi(); - if (runRmi) { - new Thread(new Runnable() { - @Override - public void run() { - CountDownLatch countDownLatch = new CountDownLatch(1); - try { - String id = UUID.randomUUID().toString().replace("-", ""); - RMISERVERID.put(project, id); - new RmiServer().run(project, id); - countDownLatch.await(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }).start(); - } - } - - public void run(@NotNull Project project, String id) { - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "8000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "8000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "8000"); - try { - final Registry registry = LocateRegistry.createRegistry(1900); - // 实例化一个WorldClock: - ServerOperation worldClock = new ServerOperation(project); - registry.rebind(id, worldClock); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/unix/UnixServer.java b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/unix/UnixServer.java new file mode 100644 index 0000000..64399e2 --- /dev/null +++ b/mybatis-idea-plugin/src/main/java/com/plugins/mybaitslog/unix/UnixServer.java @@ -0,0 +1,76 @@ +package com.plugins.mybaitslog.unix; + +import com.intellij.openapi.project.Project; +import com.plugins.mybaitslog.Config; +import com.plugins.mybaitslog.console.PrintlnUtil; +import org.jetbrains.annotations.NotNull; + +import java.net.StandardProtocolFamily; +import java.net.UnixDomainSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +/** + * A RmiServer Class + * + * @author lk + * @version 1.0 + *

date: 2023/5/12 19:20

+ */ +public class UnixServer { + + public static Map RMISERVERID = new ConcurrentHashMap(); + + public static String getId(@NotNull Project project) { + return RMISERVERID.get(project); + } + + public static void boot(@NotNull Project project) { + String id = UUID.randomUUID().toString().replace("-", ""); + RMISERVERID.put(project, id); + //无法支持到1.8后续再想办法 + /* + final boolean runRmi = Config.Idea.getRunRmi(); + if (runRmi) { + new Thread(new Runnable() { + @Override + public void run() { + try { + String id = UUID.randomUUID().toString().replace("-", ""); + RMISERVERID.put(project, id); + Path socketPath = Path + .of(System.getProperty("java.io.tmpdir")) + .resolve(id + ".socket"); + Files.deleteIfExists(socketPath); + ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(StandardProtocolFamily.UNIX); + UnixDomainSocketAddress of = UnixDomainSocketAddress.of(socketPath); + serverSocketChannel.bind(of); + while (true) { + SocketChannel socketChannel = serverSocketChannel.accept(); + ByteBuffer buf = ByteBuffer.allocate(1024); + int bytesRead = socketChannel.read(buf); + while (bytesRead > 0) { + buf.flip(); + StringBuffer stringBuffer = new StringBuffer(); + while (buf.hasRemaining()) { + stringBuffer.append((char) buf.get()); + } + buf.clear(); + PrintlnUtil.prints(project, stringBuffer.toString()); + bytesRead = socketChannel.read(buf); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + }).start(); + }*/ + } +} diff --git a/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml b/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml index 5183a9c..cf714e1 100644 --- a/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml +++ b/mybatis-idea-plugin/src/main/resources/META-INF/plugin.xml @@ -4,7 +4,7 @@ linkkou - 5.0.8.1 + 5.0.8.2 diff --git a/mybatis-plugin/build.gradle b/mybatis-plugin/build.gradle index dcd7a3e..670730f 100644 --- a/mybatis-plugin/build.gradle +++ b/mybatis-plugin/build.gradle @@ -30,11 +30,11 @@ allprojects { } group 'com.plugins.mybatislog.plugin' -version '1.0.9' +version '1.0.10' java { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" + sourceCompatibility = "8" + targetCompatibility = "8" } diff --git a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java index 8ae398c..cdb02cf 100644 --- a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java +++ b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/LogInterceptor.java @@ -22,7 +22,6 @@ import org.javatuples.Pair; import java.lang.reflect.Field; -import java.text.DateFormat; import java.util.*; import java.util.regex.Matcher; @@ -82,7 +81,7 @@ public Object intercept(Invocation invocation) throws Throwable { .setParameter(gson.toJson(completeSql.getValue1())) .setOriginalSql(originalSql); final String json = gson.toJson(sqlVO); - RmiLog.log("==> SQLStructure: " + json, this.id); + PrintlnLog.log("==> SQLStructure: " + json, this.id); } } catch (Exception e) { e.printStackTrace(); diff --git a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/MyBatisLogRmi.java b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/MyBatisLogRmi.java deleted file mode 100644 index ecda9a9..0000000 --- a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/MyBatisLogRmi.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.linkkou.mybatis.log; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface MyBatisLogRmi extends Remote { - - public String log(String name) throws RemoteException; - -} \ No newline at end of file diff --git a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/PrintlnLog.java b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/PrintlnLog.java new file mode 100644 index 0000000..9514789 --- /dev/null +++ b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/PrintlnLog.java @@ -0,0 +1,67 @@ +package com.linkkou.mybatis.log; + +import com.google.gson.internal.JavaVersion; + +import java.net.StandardProtocolFamily; +import java.net.UnixDomainSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.nio.file.Path; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * A RmiLog Class + * + * @author lk + * @version 1.0 + *

date: 2023/5/12 19:28

+ */ +public class PrintlnLog { + + private static SocketChannel socketChannel; + private static boolean connect = false; + + private static SocketChannel client(String id) { + return null; + //目前无法支持到1.8 + /*if (null == id) { + return null; + } + if (socketChannel != null && connect) { + return socketChannel; + } + Lock lock = new ReentrantLock(); //注意这个地方 + lock.lock(); + try { + Path socketPath = Path.of(System.getProperty("java.io.tmpdir")).resolve(id + ".socket"); + socketChannel = SocketChannel.open(StandardProtocolFamily.UNIX); + UnixDomainSocketAddress of = UnixDomainSocketAddress.of(socketPath); + connect = socketChannel.connect(of); + } catch (Exception e) { + e.printStackTrace(); + } finally { + lock.unlock(); + } + return socketChannel;*/ + } + + public static void log(String log, String id) { + final SocketChannel client = client(id); + if (!connect) { + System.out.println(log); + } else { + try { + ByteBuffer buf = ByteBuffer.allocate(log.length()); + buf.clear(); + buf.put(log.getBytes()); + buf.flip(); + while (buf.hasRemaining()) { + client.write(buf); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/RmiLog.java b/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/RmiLog.java deleted file mode 100644 index ebf9b65..0000000 --- a/mybatis-plugin/src/main/java/com/linkkou/mybatis/log/RmiLog.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.linkkou.mybatis.log; - -import java.net.MalformedURLException; -import java.rmi.Naming; -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.util.concurrent.CountDownLatch; - -/** - * A RmiLog Class - * - * @author lk - * @version 1.0 - *

date: 2023/5/12 19:28

- */ -public class RmiLog { - - public static void log(String log, String id) { - if (null != id) { - System.out.println(log); - } else { - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "2000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "2000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000"); - try { - MyBatisLogRmi access = (MyBatisLogRmi) Naming.lookup("rmi://localhost:1900/" + id); - access.log(log); - } catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi.java b/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi.java deleted file mode 100644 index f1d3447..0000000 --- a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.linkkou.mybatislog.sharedmemory; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface MyBatisLogRmi extends Remote { - - String log(String name) throws RemoteException; - -} \ No newline at end of file diff --git a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi2.java b/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi2.java deleted file mode 100644 index 1555651..0000000 --- a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/MyBatisLogRmi2.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.linkkou.mybatislog.sharedmemory; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface MyBatisLogRmi2 extends Remote { - - String log(String name) throws RemoteException; - -} \ No newline at end of file diff --git a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/index.java b/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/index.java deleted file mode 100644 index 851d54b..0000000 --- a/mybatis-test/src/test/java/com/linkkou/mybatislog/sharedmemory/index.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.linkkou.mybatislog.sharedmemory; - -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.ServerSocket; -import java.net.Socket; -import java.rmi.Naming; -import java.rmi.NotBoundException; -import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; -import java.rmi.server.RMISocketFactory; -import java.rmi.server.UnicastRemoteObject; -import java.util.concurrent.CountDownLatch; - -/** - * A index Class - * - * @author lk - * @version 1.0 - *

date: 2023/5/12 13:35

- */ -public class index { - - public static class ServerOperation extends UnicastRemoteObject implements MyBatisLogRmi { - - private static final long serialVersionUID = 1L; - - protected ServerOperation() throws RemoteException { - super(); - } - - @Override - public String log(String name) throws RemoteException { - System.out.println("RMI-" + name); - return "返回-成功"; - } - - } - - @Test - public void run() throws InterruptedException, MalformedURLException, NotBoundException, RemoteException { - CountDownLatch countDownLatch = new CountDownLatch(1); - // 实例化一个WorldClock: - ServerOperation worldClock = new ServerOperation(); - - - // 将此服务转换为远程服务接口: - //ServerOperation skeleton = (ServerOperation) UnicastRemoteObject.exportObject(worldClock, 0); - // 将RMI服务注册到1099端口: - Registry registry = LocateRegistry.createRegistry(1099); - Registry registry2 = LocateRegistry.createRegistry(1098); - // 注册此服务,服务名为"WorldClock": - registry.rebind("WorldClock", worldClock); - registry2.rebind("WorldClock2", worldClock); - - - // 连接到服务器localhost,端口1099: - Registry registry3 = LocateRegistry.getRegistry(1099); - // 查找名称为"WorldClock"的服务并强制转型为WorldClock接口: - MyBatisLogRmi worldClock2 = (MyBatisLogRmi) registry3.lookup("WorldClock"); - // 正常调用接口方法: - final String reponse = worldClock2.log("测试"); - // 打印调用结果: - System.out.println(reponse); - - - countDownLatch.await(); - } - - - @Test - public void run2() throws InterruptedException, IOException, NotBoundException { - CountDownLatch countDownLatch = new CountDownLatch(1); - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "2000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "2000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000"); - /* RMISocketFactory.setSocketFactory(new RMISocketFactory() { - public Socket createSocket(String host, int port) throws IOException { - Socket socket = new Socket(); - socket.setSoTimeout(5000); - socket.setSoLinger(false, 0); - socket.connect(new InetSocketAddress(host, port), 5000); - return socket; - } - - public ServerSocket createServerSocket(int port) throws IOException { - return new ServerSocket(port); - } - });*/ - // rmiregistry within the server JVM with - // port number 1900 - try { - LocateRegistry.createRegistry(1900); - LocateRegistry.createRegistry(1900); - } catch (Exception e) { - - } - // 实例化一个WorldClock: - ServerOperation worldClock = new ServerOperation(); - Naming.rebind("rmi://localhost:1900" + "/geeksforgeeks", worldClock); - countDownLatch.await(); - } - - @Test - public void run3() throws InterruptedException, IOException, NotBoundException { - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "2000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "2000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000"); - - CountDownLatch countDownLatch = new CountDownLatch(1); - MyBatisLogRmi access = (MyBatisLogRmi) Naming.lookup("rmi://localhost:1900" + "/geeksforgeeks"); - final String asdsad = access.log("asdsad"); - System.out.println(asdsad); - countDownLatch.await(); - } - - @Test - public void run4() throws InterruptedException, IOException, NotBoundException { - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "2000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "2000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "2000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "2000"); - - CountDownLatch countDownLatch = new CountDownLatch(1); - final Registry registry = LocateRegistry.createRegistry(1900); - com.linkkou.mybatis.log.MyBatisLogRmi access = (com.linkkou.mybatis.log.MyBatisLogRmi) registry.lookup("geeksforgeeks"); - final String asdsad = access.log("asdsad"); - System.out.println(asdsad); - countDownLatch.await(); - } - - @Test - public void run5(){ - CountDownLatch countDownLatch = new CountDownLatch(1); - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "8000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "8000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "8000"); - try { - final Registry registry = LocateRegistry.createRegistry(1900); - // 实例化一个WorldClock: - ServerOperation worldClock = new ServerOperation(); - registry.rebind("geeksforgeeks", worldClock); - countDownLatch.await(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void run6(){ - CountDownLatch countDownLatch = new CountDownLatch(1); - System.setProperty("sun.rmi.transport.tcp.responseTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.readTimeout", "8000"); - System.setProperty("sun.rmi.transport.connectionTimeout", "8000"); - System.setProperty("sun.rmi.transport.proxy.connectTimeout", "8000"); - System.setProperty("sun.rmi.transport.tcp.handshakeTimeout", "8000"); - try { - MyBatisLogRmi accessw = (MyBatisLogRmi) Naming.lookup("rmi://localhost:1900" + "/geeksforgeeks"); - - final Registry registry = LocateRegistry.createRegistry(1900); - // 实例化一个WorldClock: - MyBatisLogRmi access = (MyBatisLogRmi) registry.lookup("geeksforgeeks"); - countDownLatch.await(); - } catch (Exception e) { - e.printStackTrace(); - } - } -}