public static ListenerAdapter createListener(InstanceIdentifier path, String streamName) {
ListenerAdapter listener = new ListenerAdapter(path, streamName);
- lock.lock();
- listenersByInstanceIdentifier.put(path, listener);
- listenersByStreamName.put(streamName, listener);
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByInstanceIdentifier.put(path, listener);
+ listenersByStreamName.put(streamName, listener);
+ } finally {
+ lock.unlock();
+ }
return listener;
}
} catch (Exception e) {
}
}
- lock.lock();
- listenersByStreamName = new ConcurrentHashMap<>();
- listenersByInstanceIdentifier = new ConcurrentHashMap<>();
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByStreamName = new ConcurrentHashMap<>();
+ listenersByInstanceIdentifier = new ConcurrentHashMap<>();
+ } finally {
+ lock.unlock();
+ }
}
public static void removeListenerIfNoSubscriberExists(ListenerAdapter listener) {
listener.close();
} catch (Exception e) {
}
- lock.lock();
- listenersByInstanceIdentifier.remove(listener.getPath());
- listenersByStreamName.remove(listener).getStreamName();
- lock.unlock();
+ try {
+ lock.lock();
+ listenersByInstanceIdentifier.remove(listener.getPath());
+ listenersByStreamName.remove(listener.getStreamName());
+ } finally {
+ lock.unlock();
+ }
}
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.iml.varioustests;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.opendaylight.controller.sal.rest.impl.XmlToCompositeNodeProvider;
-import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.w3c.dom.Document;
-
-
-public class VariousTest {
-
- @Ignore
- @Test
- public void test() {
- String[] split = "/something:dfsa/s:sda".split("/");
- System.out.println(split.length);
- for (String str : split) {
- System.out.println(">"+str+"<");
- }
-
- }
-
- @Test
- public void loadXml() {
- TestUtils.readInputToCnSn("/varioustest/xmldata.xml", XmlToCompositeNodeProvider.INSTANCE);
-// TestUtils.normalizeCompositeNode(compositeNode, modules, schemaNodePath)
- }
-
- @Test
- public void buildXml() {
-// Document doc;
-// doc.createElementNS(namespaceURI, qualifiedName)
- }
-
-
-}
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
import java.net.URI;
import org.slf4j.Logger;
clientChannel.writeAndFlush(new PingWebSocketFrame(Unpooled.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
}
- public void close() throws InterruptedException {
- clientChannel.writeAndFlush(new CloseWebSocketFrame());
+ public void close(String reasonText) throws InterruptedException {
+ CloseWebSocketFrame closeWebSocketFrame = new CloseWebSocketFrame(1000,reasonText);
+ clientChannel.writeAndFlush(closeWebSocketFrame);
// WebSocketClientHandler will close the connection when the server
// responds to the CloseWebSocketFrame.
if (args.length > 0) {
uri = new URI(args[0]);
} else {
- uri = new URI("http://192.168.11.1:8181/opendaylight-inventory:nodes");
+ uri = new URI("http://192.168.1.101:8181/opendaylight-inventory:nodes");
}
IClientMessageCallback messageCallback = new ClientMessageCallback();
WebSocketClient webSocketClient = new WebSocketClient(uri, messageCallback);
webSocketClient.connect();
+
+ while (true) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+ String input = br.readLine();
+ if (input.equals("q")) {
+ System.out.print("Would you like to close stream? (Y = yes, empty = yes)\n");
+ input = br.readLine();
+ if (input.equals("yes") || input.isEmpty()) {
+ webSocketClient.close("opendaylight-inventory:nodes");
+ break;
+ }
+ }
+ }
}
private static class ClientMessageCallback implements IClientMessageCallback {
@Override
public void onMessageReceived(Object message) {
- logger.info("received message {}", ((TextWebSocketFrame)message).text());
+ if (message instanceof TextWebSocketFrame) {
+ logger.info("received message {}"+ ((TextWebSocketFrame)message).text());
+ }
}
}