Search in sources :

Example 1 with RegisterHandler

use of com.sun.jna.platform.win32.DdemlUtil.RegisterHandler in project jna by java-native-access.

the class DdemlUtilTest method testNameService.

@Test
public void testNameService() throws InterruptedException {
    final String serviceName = "TestService";
    final CountDownLatch latch = new CountDownLatch(1);
    StandaloneDdeClient client = null;
    StandaloneDdeClient server = null;
    try {
        client = new StandaloneDdeClient() {

            private final RegisterHandler registerHandler = new RegisterHandler() {

                public void onRegister(int transactionType, HSZ baseServiceName, HSZ instanceSpecificServiceName) {
                    if (serviceName.equals(queryString(baseServiceName))) {
                        latch.countDown();
                    }
                }
            };

            {
                registerRegisterHandler(registerHandler);
                this.initialize(Ddeml.APPCMD_CLIENTONLY);
            }
        };
        server = new StandaloneDdeClient() {

            {
                this.initialize(Ddeml.APPCMD_FILTERINITS | Ddeml.CBF_SKIP_ALLNOTIFICATIONS | Ddeml.CBF_FAIL_ALLSVRXACTIONS);
            }
        };
        server.nameService(serviceName, Ddeml.DNS_REGISTER);
        Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
    } finally {
        closeQuitely(server);
        closeQuitely(client);
    }
}
Also used : StandaloneDdeClient(com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient) CountDownLatch(java.util.concurrent.CountDownLatch) RegisterHandler(com.sun.jna.platform.win32.DdemlUtil.RegisterHandler) HSZ(com.sun.jna.platform.win32.Ddeml.HSZ) Test(org.junit.Test)

Aggregations

HSZ (com.sun.jna.platform.win32.Ddeml.HSZ)1 RegisterHandler (com.sun.jna.platform.win32.DdemlUtil.RegisterHandler)1 StandaloneDdeClient (com.sun.jna.platform.win32.DdemlUtil.StandaloneDdeClient)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1