{"action":"created","comment":{"url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/comments/33493478","id":33493478,"diff_hunk":"@@ -0,0 +1,193 @@\n+package org.eclipse.californium.elements.tcp.client;\n+\n+import io.netty.bootstrap.Bootstrap;\n+import io.netty.channel.ChannelFuture;\n+import io.netty.channel.ChannelFutureListener;\n+import io.netty.channel.nio.NioEventLoopGroup;\n+import io.netty.channel.socket.nio.NioSocketChannel;\n+import io.netty.util.concurrent.Future;\n+\n+import java.io.IOException;\n+import java.net.InetSocketAddress;\n+import java.util.concurrent.Executors;\n+import java.util.logging.Level;\n+import java.util.logging.Logger;\n+\n+import org.eclipse.californium.elements.RawData;\n+import org.eclipse.californium.elements.RawDataChannel;\n+import org.eclipse.californium.elements.StatefulConnector;\n+import org.eclipse.californium.elements.config.TCPConnectionConfig;\n+import org.eclipse.californium.elements.tcp.ConnectionInfo;\n+import org.eclipse.californium.elements.tcp.ConnectionInfo.ConnectionState;\n+import org.eclipse.californium.elements.tcp.ConnectionStateListener;\n+import org.eclipse.californium.elements.tcp.MessageInboundTransponder;\n+import org.eclipse.californium.elements.tcp.server.RemoteConnectionListener;\n+\n+public class TcpClientConnector implements StatefulConnector, RemoteConnectionListener {\n+\n+\tprivate static final Logger LOG = Logger.getLogger( TcpClientConnector.class.getName() );\n+\n+\tprivate final MessageInboundTransponder transponder;\n+\tprivate final TCPConnectionConfig cfg;\n+\n+\tprivate InetSocketAddress netAddr;\n+\tprivate NioEventLoopGroup workerPool;\n+\tprivate ChannelFuture communicationChannel;\n+\tprivate ConnectionState state = ConnectionState.DISCONNECTED;\n+\n+\tprivate ConnectionStateListener csl;\n+\n+\n+\tpublic TcpClientConnector(final TCPConnectionConfig cfg) {\n+\t\tthis.cfg = cfg;\n+\t\ttransponder = new MessageInboundTransponder(cfg.getCallBackExecutor() != null ? \n+\t\t\t\tcfg.getCallBackExecutor() : Executors.newCachedThreadPool());\n+\t\tthis.csl = cfg.getListener();\n+\t}\n+\n+\n+\n+\t@Override\n+\tpublic void start() throws IOException {\n+\t\tstart(false);\n+\t}\n+\n+\t@Override\n+\tpublic void start(final boolean wait) throws IOException {\n+\t\tLOG.info(\"Staring TCP CLIENT connector\");\n+\t\tnetAddr = new InetSocketAddress(cfg.getRemoteAddress(), cfg.getRemotePort());\n+\t\tworkerPool = new NioEventLoopGroup();\n+\n+\t\tfinal TcpClientChannelInitializer init = new TcpClientChannelInitializer(transponder, this);\n+\t\tif(cfg.isSecured()) {\n+\t\t\tinit.addTLS(cfg.getSSlContext());\n+\t\t}\n+\n+\t\tfinal Bootstrap bootstrap = new Bootstrap();\n+\t\tbootstrap.group(workerPool)\n+\t\t\t\t .remoteAddress(netAddr)\n+\t\t\t\t .channel(NioSocketChannel.class)\n+\t\t\t\t .handler(init);\n+\n+\t\tincomingConnectionStateChange(new ConnectionInfo(ConnectionState.CONNECTING, netAddr));\n+\t\tcommunicationChannel = bootstrap.connect();\n+\t\tif(wait) {\n+\t\t\ttry {\n+\t\t\t\tcommunicationChannel.sync();\n+\t\t\t} catch (final InterruptedException e) {\n+\t\t\t\tLOG.log(Level.SEVERE, \"Waiting for connection was interupted\", e);\n+\t\t\t}\n+\t\t}\n+\t\tcommunicationChannel.addListener(new ChannelActiveListener());\n+\t}\n+\n+\t@Override\n+\tpublic void stop() {\n+\t\tif(communicationChannel != null) {\n+\t\t\ttry {\n+\t\t\t\tincomingConnectionStateChange(new ConnectionInfo(ConnectionState.DISCONNECTING, getAddress()));\n+\t\t\t\tfinal ChannelFuture closeFuture = communicationChannel.channel().closeFuture();\n+\t\t\t\tfinal Future<?> workerPoolShutdown = workerPool.shutdownGracefully();\n+\t\t\t\tboolean result = closeFuture.await(1000);\n+\t\t\t\tLOG.finest(\"Stopping Communication Channel succes?: \" + result);\n+\t\t\t\tresult = workerPoolShutdown.await(1000);\n+\t\t\t\tLOG.finest(\"Stopping WorkerPool succes?: \" + result);\n+\n+\t\t\t} catch (final InterruptedException e) {\n+\t\t\t\tLOG.log(Level.SEVERE, \"error in stop: \", e);\n+\t\t\t}\n+\t\t\tfinally {\n+\t\t\t\tincomingConnectionStateChange(new ConnectionInfo(ConnectionState.DISCONNECTING, getAddress()));\n+\t\t\t}\n+\t\t}\n+\t\tnetAddr = null;\n+\t}\n+\n+\t@Override\n+\tpublic void destroy() {\n+\t\tnetAddr = null;\n+\t\tworkerPool = null;\n+\t\tcommunicationChannel = null;\n+\t}\n+\n+\t@Override\n+\tpublic void send(final RawData msg) {\n+\t\tLOG.finest(\"Sending \" + msg.getSize() + \" byte\");\n+\t\tcommunicationChannel.channel().writeAndFlush(msg.getBytes()).addListener(new ChannelFutureListener() {\n+\n+\t\t\t@Override\n+\t\t\tpublic void operationComplete(final ChannelFuture future) throws Exception {\n+\t\t\t\tprintOperationState(future);\n+\t\t\t}\n+\t\t});\n+\t}\n+\n+\t@Override\n+\tpublic void setRawDataReceiver(final RawDataChannel messageHandler) {\n+\t\ttransponder.setRawDataChannel(messageHandler);\n+\t}\n+\n+\t@Override\n+\t/*\n+\t * returns the address resolved on start, if the netAddr is null,\n+\t * the server is not stared, resolve the address and send the new object\n+\t * the netAddr will stil be resolved once it is ask to start\n+\t * (non-Javadoc)\n+\t * @see org.eclipse.californium.elements.Connector#getAddress()\n+\t */\n+\tpublic InetSocketAddress getAddress() {\n+\t\treturn netAddr == null ? new InetSocketAddress(cfg.getRemoteAddress(), cfg.getRemotePort()) : netAddr;\n+\t}\n+\n+\t@Override\n+\tpublic ConnectionState getConnectionState() {\n+\t\treturn state;","path":"src/main/java/org/eclipse/californium/elements/tcp/client/TcpClientConnector.java","position":144,"original_position":144,"commit_id":"d849b651de581c950eec2fc632328c301395a303","original_commit_id":"d849b651de581c950eec2fc632328c301395a303","user":{"login":"Areontar","id":2413363,"avatar_url":"https://avatars.githubusercontent.com/u/2413363?v=3","gravatar_id":"","url":"https://api.github.com/users/Areontar","html_url":"https://github.com/Areontar","followers_url":"https://api.github.com/users/Areontar/followers","following_url":"https://api.github.com/users/Areontar/following{/other_user}","gists_url":"https://api.github.com/users/Areontar/gists{/gist_id}","starred_url":"https://api.github.com/users/Areontar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Areontar/subscriptions","organizations_url":"https://api.github.com/users/Areontar/orgs","repos_url":"https://api.github.com/users/Areontar/repos","events_url":"https://api.github.com/users/Areontar/events{/privacy}","received_events_url":"https://api.github.com/users/Areontar/received_events","type":"User","site_admin":false},"body":"> Do we want to return a copy here?\r\n\r\na copie of the enum?","created_at":"2015-06-29T18:09:40Z","updated_at":"2015-06-29T18:09:40Z","html_url":"https://github.com/zatar-iot/californium.element-connector/pull/2#discussion_r33493478","pull_request_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/comments/33493478"},"html":{"href":"https://github.com/zatar-iot/californium.element-connector/pull/2#discussion_r33493478"},"pull_request":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2","id":38666217,"html_url":"https://github.com/zatar-iot/californium.element-connector/pull/2","diff_url":"https://github.com/zatar-iot/californium.element-connector/pull/2.diff","patch_url":"https://github.com/zatar-iot/californium.element-connector/pull/2.patch","issue_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/2","number":2,"state":"open","locked":false,"title":"implementation of TCP and TLS (using Netty)","user":{"login":"Areontar","id":2413363,"avatar_url":"https://avatars.githubusercontent.com/u/2413363?v=3","gravatar_id":"","url":"https://api.github.com/users/Areontar","html_url":"https://github.com/Areontar","followers_url":"https://api.github.com/users/Areontar/followers","following_url":"https://api.github.com/users/Areontar/following{/other_user}","gists_url":"https://api.github.com/users/Areontar/gists{/gist_id}","starred_url":"https://api.github.com/users/Areontar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Areontar/subscriptions","organizations_url":"https://api.github.com/users/Areontar/orgs","repos_url":"https://api.github.com/users/Areontar/repos","events_url":"https://api.github.com/users/Areontar/events{/privacy}","received_events_url":"https://api.github.com/users/Areontar/received_events","type":"User","site_admin":false},"body":"This is the impl of netty (TCP and TLS) into CF.element.  ","created_at":"2015-06-26T16:28:56Z","updated_at":"2015-06-29T18:09:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e031dd3fb5054988c12cf6863b161888c511c426","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2/commits","review_comments_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2/comments","review_comment_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/2/comments","statuses_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/statuses/d849b651de581c950eec2fc632328c301395a303","head":{"label":"zatar-iot:tcp_impl","ref":"tcp_impl","sha":"d849b651de581c950eec2fc632328c301395a303","user":{"login":"zatar-iot","id":7365347,"avatar_url":"https://avatars.githubusercontent.com/u/7365347?v=3","gravatar_id":"","url":"https://api.github.com/users/zatar-iot","html_url":"https://github.com/zatar-iot","followers_url":"https://api.github.com/users/zatar-iot/followers","following_url":"https://api.github.com/users/zatar-iot/following{/other_user}","gists_url":"https://api.github.com/users/zatar-iot/gists{/gist_id}","starred_url":"https://api.github.com/users/zatar-iot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zatar-iot/subscriptions","organizations_url":"https://api.github.com/users/zatar-iot/orgs","repos_url":"https://api.github.com/users/zatar-iot/repos","events_url":"https://api.github.com/users/zatar-iot/events{/privacy}","received_events_url":"https://api.github.com/users/zatar-iot/received_events","type":"Organization","site_admin":false},"repo":{"id":33694895,"name":"californium.element-connector","full_name":"zatar-iot/californium.element-connector","owner":{"login":"zatar-iot","id":7365347,"avatar_url":"https://avatars.githubusercontent.com/u/7365347?v=3","gravatar_id":"","url":"https://api.github.com/users/zatar-iot","html_url":"https://github.com/zatar-iot","followers_url":"https://api.github.com/users/zatar-iot/followers","following_url":"https://api.github.com/users/zatar-iot/following{/other_user}","gists_url":"https://api.github.com/users/zatar-iot/gists{/gist_id}","starred_url":"https://api.github.com/users/zatar-iot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zatar-iot/subscriptions","organizations_url":"https://api.github.com/users/zatar-iot/orgs","repos_url":"https://api.github.com/users/zatar-iot/repos","events_url":"https://api.github.com/users/zatar-iot/events{/privacy}","received_events_url":"https://api.github.com/users/zatar-iot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zatar-iot/californium.element-connector","description":"Californium project","fork":true,"url":"https://api.github.com/repos/zatar-iot/californium.element-connector","forks_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/forks","keys_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/teams","hooks_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/hooks","issue_events_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/events{/number}","events_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/events","assignees_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/assignees{/user}","branches_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/branches{/branch}","tags_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/tags","blobs_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/refs{/sha}","trees_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/statuses/{sha}","languages_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/languages","stargazers_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/stargazers","contributors_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/contributors","subscribers_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/subscribers","subscription_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/subscription","commits_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/commits{/sha}","git_commits_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/commits{/sha}","comments_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/comments{/number}","issue_comment_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/comments{/number}","contents_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/contents/{+path}","compare_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/merges","archive_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/downloads","issues_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues{/number}","pulls_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls{/number}","milestones_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/milestones{/number}","notifications_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/labels{/name}","releases_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/releases{/id}","created_at":"2015-04-09T21:59:04Z","updated_at":"2015-04-09T21:59:04Z","pushed_at":"2015-06-29T14:55:00Z","git_url":"git://github.com/zatar-iot/californium.element-connector.git","ssh_url":"git@github.com:zatar-iot/californium.element-connector.git","clone_url":"https://github.com/zatar-iot/californium.element-connector.git","svn_url":"https://github.com/zatar-iot/californium.element-connector","homepage":null,"size":208,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"zatar-iot:tcp_tls_impl","ref":"tcp_tls_impl","sha":"98aaaa4f9172063aa698daa83eefe64899b8cad7","user":{"login":"zatar-iot","id":7365347,"avatar_url":"https://avatars.githubusercontent.com/u/7365347?v=3","gravatar_id":"","url":"https://api.github.com/users/zatar-iot","html_url":"https://github.com/zatar-iot","followers_url":"https://api.github.com/users/zatar-iot/followers","following_url":"https://api.github.com/users/zatar-iot/following{/other_user}","gists_url":"https://api.github.com/users/zatar-iot/gists{/gist_id}","starred_url":"https://api.github.com/users/zatar-iot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zatar-iot/subscriptions","organizations_url":"https://api.github.com/users/zatar-iot/orgs","repos_url":"https://api.github.com/users/zatar-iot/repos","events_url":"https://api.github.com/users/zatar-iot/events{/privacy}","received_events_url":"https://api.github.com/users/zatar-iot/received_events","type":"Organization","site_admin":false},"repo":{"id":33694895,"name":"californium.element-connector","full_name":"zatar-iot/californium.element-connector","owner":{"login":"zatar-iot","id":7365347,"avatar_url":"https://avatars.githubusercontent.com/u/7365347?v=3","gravatar_id":"","url":"https://api.github.com/users/zatar-iot","html_url":"https://github.com/zatar-iot","followers_url":"https://api.github.com/users/zatar-iot/followers","following_url":"https://api.github.com/users/zatar-iot/following{/other_user}","gists_url":"https://api.github.com/users/zatar-iot/gists{/gist_id}","starred_url":"https://api.github.com/users/zatar-iot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zatar-iot/subscriptions","organizations_url":"https://api.github.com/users/zatar-iot/orgs","repos_url":"https://api.github.com/users/zatar-iot/repos","events_url":"https://api.github.com/users/zatar-iot/events{/privacy}","received_events_url":"https://api.github.com/users/zatar-iot/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zatar-iot/californium.element-connector","description":"Californium project","fork":true,"url":"https://api.github.com/repos/zatar-iot/californium.element-connector","forks_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/forks","keys_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/teams","hooks_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/hooks","issue_events_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/events{/number}","events_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/events","assignees_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/assignees{/user}","branches_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/branches{/branch}","tags_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/tags","blobs_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/refs{/sha}","trees_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/statuses/{sha}","languages_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/languages","stargazers_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/stargazers","contributors_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/contributors","subscribers_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/subscribers","subscription_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/subscription","commits_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/commits{/sha}","git_commits_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/git/commits{/sha}","comments_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/comments{/number}","issue_comment_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/comments{/number}","contents_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/contents/{+path}","compare_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/merges","archive_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/downloads","issues_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues{/number}","pulls_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls{/number}","milestones_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/milestones{/number}","notifications_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/labels{/name}","releases_url":"https://api.github.com/repos/zatar-iot/californium.element-connector/releases{/id}","created_at":"2015-04-09T21:59:04Z","updated_at":"2015-04-09T21:59:04Z","pushed_at":"2015-06-29T14:55:00Z","git_url":"git://github.com/zatar-iot/californium.element-connector.git","ssh_url":"git@github.com:zatar-iot/californium.element-connector.git","clone_url":"https://github.com/zatar-iot/californium.element-connector.git","svn_url":"https://github.com/zatar-iot/californium.element-connector","homepage":null,"size":208,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2"},"html":{"href":"https://github.com/zatar-iot/californium.element-connector/pull/2"},"issue":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/2"},"comments":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/zatar-iot/californium.element-connector/statuses/d849b651de581c950eec2fc632328c301395a303"}}}}