<commit_before>/*
 * Copyright 1999-2010 <NAME> (l.garulli--at--orientechnologies.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.orientechnologies.orient.server.network.protocol.distributed;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collection;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.OSecurityException;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryInputStream;
import com.orientechnologies.orient.enterprise.channel.distributed.OChannelDistributedProtocol;
import com.orientechnologies.orient.server.OServerMain;
import com.orientechnologies.orient.server.handler.distributed.ODistributedServerManager;
import com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary;
import com.orientechnologies.orient.server.replication.ODistributedDatabaseInfo;
import com.orientechnologies.orient.server.replication.ODistributedNode;
import com.orientechnologies.orient.server.replication.ODistributedStorage;
import com.orientechnologies.orient.server.replication.ODistributedSynchronizationException;
import com.orientechnologies.orient.server.replication.OOperationLog;

/**
 * Extends binary protocol to include cluster commands.
 * 
 * @author <NAME> (l.garulli--at--orientechnologies.com)
 * 
 */
public class ONetworkProtocolDistributed extends ONetworkProtocolBinary implements OCommandOutputListener {
	private ODistributedServerManager	manager;
	private String										clientId;

	public ONetworkProtocolDistributed() {
		super("OrientDB DistributedBinaryNetworkProtocolListener");

		manager = OServerMain.server().getHandler(ODistributedServerManager.class);
		if (manager == null)
			throw new OConfigurationException(
					"Cannot find a ODistributedServerDiscoveryManager instance registered as handler. Check the server configuration in the handlers section.");
	}

	@Override
	protected void parseCommand() throws IOException, InterruptedException {

		if (clientId == null && data.clientId != null)
			// ASSIGN CLIENT-ID ONCE
			clientId = data.clientId.substring(ODistributedStorage.DNODE_PREFIX.length());

		// DISTRIBUTED SERVER REQUESTS
		switch (lastRequestType) {

		case OChannelDistributedProtocol.REQUEST_DISTRIBUTED_SYNCHRONIZE: {
			data.commandInfo = "Synchronization between nodes";
			final ODocument cfg = new ODocument(channel.readBytes());

			sendOk(lastClientTxId);

			final ORecordOperation op = new ORecordOperation();
<commit_msg>Fixed bug found by Anton in binary protocol on clientId in OPEN and CONNECT<commit_after>/*
 * Copyright 1999-2010 <NAME> (l.garulli--at--orientechnologies.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.orientechnologies.orient.server.network.protocol.distributed;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collection;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.command.OCommandOutputListener;
import com.orientechnologies.orient.core.db.record.ORecordOperation;
import com.orientechnologies.orient.core.db.tool.ODatabaseImport;
import com.orientechnologies.orient.core.exception.OConfigurationException;
import com.orientechnologies.orient.core.exception.OSecurityException;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryInputStream;
import com.orientechnologies.orient.enterprise.channel.distributed.OChannelDistributedProtocol;
import com.orientechnologies.orient.server.OServerMain;
import com.orientechnologies.orient.server.handler.distributed.ODistributedServerManager;
import com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary;
import com.orientechnologies.orient.server.replication.ODistributedDatabaseInfo;
import com.orientechnologies.orient.server.replication.ODistributedNode;
import com.orientechnologies.orient.server.replication.ODistributedStorage;
import com.orientechnologies.orient.server.replication.ODistributedSynchronizationException;
import com.orientechnologies.orient.server.replication.OOperationLog;

/**
 * Extends binary protocol to include cluster commands.
 * 
 * @author <NAME> (<EMAIL>--at--<EMAIL>)
 * 
 */
public class ONetworkProtocolDistributed extends ONetworkProtocolBinary implements OCommandOutputListener {
	private ODistributedServerManager	manager;
	private String										clientId;

	public ONetworkProtocolDistributed() {
		super("OrientDB DistributedBinaryNetworkProtocolListener");

		manager = OServerMain.server().getHandler(ODistributedServerManager.class);
		if (manager == null)
			throw new OConfigurationException(
					"Cannot find a ODistributedServerDiscoveryManager instance registered as handler. Check the server configuration in the handlers section.");
	}

	@Override
	protected void parseCommand() throws IOException, InterruptedException {

		if (clientId == null && data.clientId != null && data.clientId.startsWith(ODistributedStorage.DNODE_PREFIX))
			// ASSIGN CLIENT-ID ONCE
			clientId = data.clientId.substring(ODistributedStorage.DNODE_PREFIX.length());

		// DISTRIBUTED SERVER REQUESTS
		switch (lastRequestType) {

		case OChannelDistributedProtocol.REQUEST_DISTRIBUTED_SYNCHRONIZE: {
			data.commandInfo = "Synchronization between nodes";
			final ODocument cfg = new ODocument(channel.readBytes());

			sendOk(lastClientTxId);

			final ORecordOperation op = new ORecordOperation();

{'fraction_non_alphanumeric': 0.08477214831587886, 'fraction_numerical': 0.003396546844041891, 'mean_word_length': 5.881207400194742, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1572234', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1927, 'n_words': 454}