this will be called from core when layer-lisenter object when it emit connection
500387
function Communication() {
		// setup abstract layer
		core.CommunicationAbstract.apply(this, arguments);

		// just relay message object they do not need to be parsed
		this.object.on('message', this.emit.bind(this, 'message'));

		// when the remote request a method, the methods should exists in .handlers
		var self = this;
		this.handlers.close = function () {
			this.callback();
			self.emit('close');
		};
	}
311050
def _connected(self, watcher, events):
        """"""
        self.connected = True
        self._finish()
        self.deferred.callback(self.sock)
93367
function (options, onConnect) {
    var self = this;
    EventEmitter.call(this);

    this.options = options;

    // debugging
    this.debug_enabled = options.debug;
    this.handshook = false;

    // received data which could not be parsed into messages yet
    this.data = '';

    // determine correct call of net.connect
    var cb = function () {
        connected.call(self);
        onConnect.call(self);
    };

    if (options.path) {
        this.debug("Trying to establish connection to unix socket %s", options.path);
        this.client = net.connect(options.path, cb);
    } else {
        this.debug("Trying to establish connection to %s on port %s", options.host, options.port);
        this.client = net.connect(options.port, options.host, cb);
    }

    // when data is received
    this.client.on('data', function (data) {
        var obj = dezeusify.call(self, data.toString('utf8'));
        obj.forEach(function (item) {
            received.call(self, item);
        });
    });

    // when the connection is closed
    this.client.on('end', function () {
        disconnected.call(self);
    });

    this.client.on('error', function (err) {
        self.debug("Whoops, an error occurred: %s", err.message);
        throw new Error(util.format("A connection error occurred: %s", err.message));
    });

    // when a new listener is added to this object, we'll want to check if we should notify the server
    this.on('newListener', function (evt) {
        this.debug("A new event listener was added");
        if (evt.toUpperCase() === evt && !this.subscribedEvents.indexOf(evt) !== -1) {
            subscribeServerEvent.call(self, evt);
        }
    });

    this.subscribedEvents = [];
    this.waitingCallbacks = [];
}
481672
def on_connected(self, connection):
        
        log.info('PikaClient: connected to RabbitMQ')
        self.connected = True
        self.in_channel = self.connection.channel(self.on_channel_open)
747735
function Layer () {
    Layer.superclass.constructor.call(this)

    var s = Director.sharedDirector.winSize

    this.isRelativeAnchorPoint = false
    this.anchorPoint = ccp(0.5, 0.5)
    this.contentSize = s

    if (!Director.sharedDirector.isTouchScreen) {
        events.addPropertyListener(this, 'isMouseEnabled', 'change', function () {
            if (this.isRunning) {
                if (this.isMouseEnabled) {
                    EventDispatcher.sharedDispatcher.addMouseDelegate({delegate: this, priority: this.mouseDelegatePriority})
                } else {
                    EventDispatcher.sharedDispatcher.removeMouseDelegate({delegate: this})
                }
            }
        }.bind(this))

        events.addPropertyListener(this, 'isKeyboardEnabled', 'change', function () {
            if (this.isRunning) {
                if (this.isKeyboardEnabled) {
                    EventDispatcher.sharedDispatcher.addKeyboardDelegate({delegate: this, priority: this.keyboardDelegatePriority})
                } else {
                    EventDispatcher.sharedDispatcher.removeKeyboardDelegate({delegate: this})
                }
            }
        }.bind(this))
    }
}
386174
@Override
	protected void initialize() {
		super.initialize();
		ClientLayerTreeInfo ltwli = (ClientLayerTreeInfo) mapWidget.getMapModel().getMapInfo()
				.getWidgetInfo(ClientLayerTreeInfo.IDENTIFIER);
		setIconSize(ltwli == null ? GltLayout.layerTreeIconSize : ltwli.getIconSize());

		for (Layer<?> layer : mapModel.getLayers()) {
			registrations.add(layer.addLayerChangedHandler(new LayerChangedHandler() {

				public void onLabelChange(LayerLabeledEvent event) {
					GWT.log("Legend: onLabelChange() - " + event.getLayer().getLabel());
					// find the node & update the icon
					for (TreeNode node : tree.getAllNodes()) {
						if (node.getName().equals(event.getLayer().getLabel()) && node instanceof LayerTreeTreeNode) {
							((LayerTreeTreeNode) node).updateIcon();
						}
					}
				}

				public void onVisibleChange(LayerShownEvent event) {
					GWT.log("Legend: onVisibleChange() - " + event.getLayer().getLabel());
					// find the node & update the icon
					for (TreeNode node : tree.getAllNodes()) {
						if (node.getName().equals(event.getLayer().getLabel()) && node instanceof LayerTreeTreeNode) {
							((LayerTreeTreeNode) node).updateIcon();
						}
					}
				}
			}));
			registrations.add(layer.addLayerStyleChangedHandler(new LayerStyleChangedHandler() {

				public void onLayerStyleChange(LayerStyleChangeEvent event) {
					GWT.log("Legend: onLayerStyleChange()");
					Layer<?> layer = event.getLayer();
					if (layer instanceof VectorLayer) {
						for (LayerTreeLegendItemNode node : legendIcons.get(layer)) {
							node.updateStyle((VectorLayer) layer);
						}
					}
				}
			}));

			if (layer instanceof VectorLayer) {
				VectorLayer vl = (VectorLayer) layer;
				registrations.add(vl.addLayerFilteredHandler(new LayerFilteredHandler() {

					public void onFilterChange(LayerFilteredEvent event) {
						GWT.log("Legend: onLayerFilterChange() - " + event.getLayer().getLabel());
						// find the node & update the icon
						for (TreeNode node : tree.getAllNodes()) {
							if (node.getName().equals(event.getLayer().getLabel()) 
									&& node instanceof LayerTreeTreeNode) {
								((LayerTreeTreeNode) node).updateIcon();
							}
						}
					}
				}));
			}
		}
	}
952997
private void init() {
		view.setLayerTitle(layer.getTitle());
		view.setLayerVisible(layer.isMarkedAsVisible());

		updateVisibilityToggle();

		mapPresenter.getEventBus().addViewPortChangedHandler(new ViewPortChangedHandler() {
			@Override
			public void onViewPortChanged(ViewPortChangedEvent event) {
				updateVisibilityToggle();
			}
		});

		// React to layer visibility events:
		mapPresenter.getEventBus().addLayerVisibilityHandler(new LayerVisibilityHandler() {

			@Override
			public void onShow(LayerShowEvent event) {
			}

			@Override
			public void onHide(LayerHideEvent event) {
			}

			@Override
			public void onVisibilityMarked(LayerVisibilityMarkedEvent event) {
				view.setLayerVisible(layer.isMarkedAsVisible());

			}
		}, this.layer);
	}
978158
def on_connect(self, connection):
        ""
        self._sock = connection._sock
        self._buffer = SocketBuffer(self._sock, self.socket_read_size)
        self.encoder = connection.encoder
228646
function() {
      
      var layer = this.layer;
      
      Event.addListener(this.element, 'mousedown', this.onMouseDown, this, true);
      Event.addListener(this.element, 'mouseup', this.onMouseUp, this, true);
      Event.addListener(this.element, 'mousemove', this.onMouseMove, this, true);
      Event.addListener(this.element, 'mouseout', this.onMouseUp, this, true);
      
      layer.eventAddWire.subscribe(this.draw, this, true);
      layer.eventRemoveWire.subscribe(this.draw, this, true);
      layer.eventAddContainer.subscribe(this.draw, this, true);
      layer.eventRemoveContainer.subscribe(this.draw, this, true);
      layer.eventContainerDragged.subscribe(this.draw, this, true);
      layer.eventContainerResized.subscribe(this.draw, this, true);

      Event.addListener(this.layer.el, "scroll", this.onLayerScroll, this, true);
   }
49711
function (ui, done) {

        var bs = ui.bs;

        ui.clients.on("connection", function (client) {

            client.emit("ui:connection", ui.options.toJS());

            ui.options.get("clientFiles").map(function (item) {
                if (item.get("active")) {
                    ui.addElement(client, item.toJS());
                }
            });
        });

        ui.socket.on("connection", function (client) {

            client.emit("connection", bs.getOptions().toJS());

            client.emit("ui:connection", ui.options.toJS());

            client.on("ui:get:options", function () {
                client.emit("ui:receive:options", {
                    bs: bs.getOptions().toJS(),
                    ui: ui.options.toJS()
                });
            });

            // proxy client events
            client.on("ui:client:proxy", function (evt) {
                ui.clients.emit(evt.event, evt.data);
            });

            client.on("ui", function (data) {
                ui.delegateEvent(data);
            });
        });
        done();
    }
884118
def getConnection(self, lfrom, lto):
        
        for connection in self.connections:
            if connection.fromLayer.name == lfrom and \
               connection.toLayer.name == lto:
                return connection
        raise NetworkError('Connection was not found.', (lfrom, lto))
1198540
function(handler, priority) {
        if(typeof handler !== 'function') {
          throw new Error('Middleware must be a function.');
        }

        if(typeof priority !== 'undefined') handler.priority = priority;
        _layerList.push(handler);
        return _inst;
      }
703581
public static function onConnect($callback_key, $fd, $from_id) {
		if (isset(self::$_listener[$callback_key])) {
			call_user_func(self::$_listener[$callback_key], 'connect', $fd, $from_id);
		}
	}
165056
function (callback) {
            debug('');

            self.repository.on('connect', function () {
              self.emit('connect');
            });

            self.repository.on('disconnect', function () {
              self.emit('disconnect');
            });

            self.repository.connect(callback);
          }
1093573
function Connection(ws, logger) {
        events.EventEmitter.call(this);

        this._ws = ws;
        this._logger = logger;
        this._connected = true;

        this._ws.on("message", this._receive.bind(this));
        this._ws.once("close", this.close.bind(this));
    }
661138
def connect(self, callback, ref=False, position='first',
                before=None, after=None):
        
        self._connect_emitters(True)
        return EventEmitter.connect(self, callback, ref, position,
                                    before, after)
636421
@Override
    public void notifyLayerChanged(FeatureProvider provider,
                                   Integer layerRefreshOld,
                                   Integer layerRefreshNew,
                                   Integer layerDisplayOld,
                                   Integer layerDisplayNew)
    {
        if (provider.hasFeature(Refreshable.class))
        {
            final Refreshable refreshable = provider.getFeature(Refreshable.class);
            getLayer(layerRefreshOld).remove(refreshable);
            getLayer(layerRefreshNew).add(refreshable);
            indexs.add(layerRefreshNew);
        }
    }