Search in sources :

Example 11 with VersionedDataInputStream

use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.

the class GMSMemberJUnitTest method testGMSMemberBackwardCompatibility.

/**
   * <p>
   * GEODE-2875 - adds vmKind to on-wire form of GMSMember.writeEssentialData
   * </p>
   * <p>
   * This must be backward-compatible with Geode 1.0 (Version.GFE_90)
   * </p>
   * 
   * @throws Exception
   */
@Test
public void testGMSMemberBackwardCompatibility() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    MemberAttributes attributes = new MemberAttributes(10, 20, 1, 2, "member", null, null);
    GMSMember member = new GMSMember();
    member.setAttributes(attributes);
    DataOutput dataOutput = new DataOutputStream(baos);
    member.writeEssentialData(dataOutput);
    // vmKind should be transmitted to a member with the current version
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    DataInput dataInput = new DataInputStream(bais);
    GMSMember newMember = new GMSMember();
    newMember.readEssentialData(dataInput);
    assertEquals(1, newMember.getVmKind());
    // vmKind should not be transmitted to a member with version GFE_90 or earlier
    dataOutput = new HeapDataOutputStream(Version.GFE_90);
    member.writeEssentialData(dataOutput);
    bais = new ByteArrayInputStream(baos.toByteArray());
    dataInput = new VersionedDataInputStream(new DataInputStream(bais), Version.GFE_90);
    newMember = new GMSMember();
    newMember.readEssentialData(dataInput);
    assertEquals(0, newMember.getVmKind());
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) MemberAttributes(org.apache.geode.distributed.internal.membership.MemberAttributes) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 12 with VersionedDataInputStream

use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.

the class HandShake method accept.

public void accept(OutputStream out, InputStream in, byte epType, int qSize, byte communicationMode, Principal principal) throws IOException {
    DataOutputStream dos = new DataOutputStream(out);
    DataInputStream dis;
    if (clientVersion.compareTo(Version.CURRENT) < 0) {
        dis = new VersionedDataInputStream(in, clientVersion);
        dos = new VersionedDataOutputStream(dos, clientVersion);
    } else {
        dis = new DataInputStream(in);
    }
    // Write ok reply
    if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && principal != null) {
        dos.writeByte(REPLY_WAN_CREDENTIALS);
    } else {
        // byte 59
        dos.writeByte(REPLY_OK);
    }
    // additional byte of wan site needs to send for Gateway BC
    if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
        Version.writeOrdinal(dos, ServerHandShakeProcessor.currentServerVersion.ordinal(), true);
    }
    dos.writeByte(epType);
    dos.writeInt(qSize);
    // Write the server's member
    DistributedMember member = this.system.getDistributedMember();
    ServerHandShakeProcessor.writeServerMember(member, dos);
    // Write no message
    dos.writeUTF("");
    // Write delta-propagation property value if this is not WAN.
    if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && this.clientVersion.compareTo(Version.GFE_61) >= 0) {
        dos.writeBoolean(((InternalDistributedSystem) this.system).getConfig().getDeltaPropagation());
    }
    // and principal not equal to null then send the credentials also
    if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && principal != null) {
        sendCredentialsForWan(dos, dis);
    }
    // on the remote side of the gateway
    if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && this.clientVersion.compareTo(Version.GFE_66) >= 0 && ServerHandShakeProcessor.currentServerVersion.compareTo(Version.GFE_66) >= 0) {
        dos.writeByte(((InternalDistributedSystem) this.system).getDistributionManager().getDistributedSystemId());
    }
    if ((communicationMode == Acceptor.GATEWAY_TO_GATEWAY) && this.clientVersion.compareTo(Version.GFE_80) >= 0 && ServerHandShakeProcessor.currentServerVersion.compareTo(Version.GFE_80) >= 0) {
        int pdxSize = PeerTypeRegistration.getPdxRegistrySize();
        dos.writeInt(pdxSize);
    }
    // Flush
    dos.flush();
}
Also used : DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream)

Example 13 with VersionedDataInputStream

use of org.apache.geode.internal.VersionedDataInputStream in project geode by apache.

the class GatewaySenderEventImpl method fromData.

public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    short version = in.readShort();
    if (version != VERSION) {
    // warning?`
    }
    this.isInitialized = true;
    this.action = in.readInt();
    this.numberOfParts = in.readInt();
    // this._id = in.readUTF();
    if (version < 0x11 && (in instanceof InputStream) && InternalDataSerializer.getVersionForDataStream(in) == Version.CURRENT) {
        in = new VersionedDataInputStream((InputStream) in, Version.GFE_701);
    }
    this.id = (EventID) DataSerializer.readObject(in);
    // TODO:Asif ; Check if this violates Barry's logic of not assiging VM
    // specific Token.FROM_GATEWAY
    // and retain the serialized Token.FROM_GATEWAY
    // this._id.setFromGateway(false);
    this.regionPath = DataSerializer.readString(in);
    this.valueIsObject = in.readByte();
    deserializeKey(in);
    this.value = DataSerializer.readByteArray(in);
    this.callbackArgument = (GatewaySenderEventCallbackArgument) DataSerializer.readObject(in);
    this.possibleDuplicate = in.readBoolean();
    this.creationTime = in.readLong();
    this.bucketId = in.readInt();
    this.shadowKey = in.readLong();
    this.versionTimeStamp = in.readLong();
// TODO should this call initializeKey()?
}
Also used : VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) InputStream(java.io.InputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream)

Aggregations

VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)13 DataInputStream (java.io.DataInputStream)12 IOException (java.io.IOException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 DataOutputStream (java.io.DataOutputStream)7 VersionedDataOutputStream (org.apache.geode.internal.VersionedDataOutputStream)7 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)5 EOFException (java.io.EOFException)4 GemFireConfigException (org.apache.geode.GemFireConfigException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 InputStream (java.io.InputStream)3 Socket (java.net.Socket)3 SSLException (javax.net.ssl.SSLException)3 UnsupportedVersionException (org.apache.geode.cache.UnsupportedVersionException)3 Version (org.apache.geode.internal.Version)3 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)3 Test (org.junit.Test)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UnknownHostException (java.net.UnknownHostException)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2