RemoteConnection(final StreamConnection connection, final SslChannel sslChannel, final OptionMap optionMap, final RemoteConnectionProvider remoteConnectionProvider) { this.connection = connection; this.messageReader = new MessageReader(connection.getSourceChannel(), writeListener.queue); this.sslChannel = sslChannel; this.optionMap = optionMap; heartbeatInterval = optionMap.get(RemotingOptions.HEARTBEAT_INTERVAL, RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL); Messages.conn.tracef("Initialized connection from %s to %s with options %s", connection.getPeerAddress(), connection.getLocalAddress(), optionMap); this.executor = remoteConnectionProvider.getExecutor(); this.remoteConnectionProvider = remoteConnectionProvider; }
/*Lets suppose we have a class "MessageReader" that has a method printMessage * that for some reason needs to receive the message to be printed from a function, * not directly a value.*/ function MessageReader() { this.value = "This is NOT a message and is not supposed to be readed!"; } /*getMessage needs to return a string that will be printed!*/ MessageReader.prototype.printMessage = function(getMessage) { console.log(getMessage.apply(this, [])); } function Message(value) { this.value = value; } Message.prototype.getMessage = function() { return this.value; } var myMessageReader = new MessageReader(); var myMessage1 = new Message("This is a simple message"); var myMessage2 = new Message("This is another simple message"); /*This will print the wrong message:*/ myMessageReader.printMessage(myMessage1.getMessage); /*But this works!*/ myMessageReader.printMessage(myMessage2.getMessage.bind(myMessage2));
RemoteConnection(final StreamConnection connection, final SslChannel sslChannel, final OptionMap optionMap, final RemoteConnectionProvider remoteConnectionProvider) { this.connection = connection; this.messageReader = new MessageReader(connection.getSourceChannel(), writeListener.queue); this.sslChannel = sslChannel; this.optionMap = optionMap; heartbeatInterval = optionMap.get(RemotingOptions.HEARTBEAT_INTERVAL, RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL); Messages.conn.tracef("Initialized connection from %s to %s with options %s", connection.getPeerAddress(), connection.getLocalAddress(), optionMap); this.executor = remoteConnectionProvider.getExecutor(); this.remoteConnectionProvider = remoteConnectionProvider; }