Search in sources :

Example 6 with DurableClientAttributes

use of org.apache.geode.distributed.DurableClientAttributes in project geode by apache.

the class InternalDistributedMember method writeExternal.

/**
   * For Externalizable
   *
   * @see Externalizable
   */
public void writeExternal(ObjectOutput out) throws IOException {
    Assert.assertTrue(netMbr.getVmKind() > 0);
    // do it the way we like
    byte[] address = getInetAddress().getAddress();
    // IPv6 compatible
    out.writeInt(address.length);
    out.write(address);
    out.writeInt(getPort());
    DataSerializer.writeString(this.hostName, out);
    int flags = 0;
    if (netMbr.isNetworkPartitionDetectionEnabled())
        flags |= NPD_ENABLED_BIT;
    if (netMbr.preferredForCoordinator())
        flags |= COORD_ENABLED_BIT;
    if (this.isPartial)
        flags |= PARTIAL_ID_BIT;
    // always write product version but enable reading from older versions
    // that do not have it
    flags |= VERSION_BIT;
    out.writeByte((byte) (flags & 0xff));
    out.writeInt(netMbr.getDirectPort());
    out.writeInt(netMbr.getProcessId());
    out.writeInt(netMbr.getVmKind());
    out.writeInt(netMbr.getVmViewId());
    DataSerializer.writeStringArray(netMbr.getGroups(), out);
    DataSerializer.writeString(netMbr.getName(), out);
    DataSerializer.writeString(this.uniqueTag, out);
    DurableClientAttributes attributes = netMbr.getDurableClientAttributes();
    DataSerializer.writeString(attributes == null ? "" : attributes.getId(), out);
    DataSerializer.writeInteger(Integer.valueOf(attributes == null ? 300 : attributes.getTimeout()), out);
    Version.writeOrdinal(out, netMbr.getVersionOrdinal(), true);
    netMbr.writeAdditionalData(out);
}
Also used : DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Example 7 with DurableClientAttributes

use of org.apache.geode.distributed.DurableClientAttributes in project geode by apache.

the class InternalDistributedMember method fromDataPre_GFE_7_1_0_0.

public void fromDataPre_GFE_7_1_0_0(DataInput in) throws IOException, ClassNotFoundException {
    InetAddress inetAddr = DataSerializer.readInetAddress(in);
    int port = in.readInt();
    this.hostName = DataSerializer.readString(in);
    this.hostName = SocketCreator.resolve_dns ? SocketCreator.getCanonicalHostName(inetAddr, hostName) : inetAddr.getHostAddress();
    int flags = in.readUnsignedByte();
    boolean sbEnabled = (flags & NPD_ENABLED_BIT) != 0;
    boolean elCoord = (flags & COORD_ENABLED_BIT) != 0;
    this.isPartial = (flags & PARTIAL_ID_BIT) != 0;
    int dcPort = in.readInt();
    int vmPid = in.readInt();
    int vmKind = in.readUnsignedByte();
    String[] groups = DataSerializer.readStringArray(in);
    int vmViewId = -1;
    String name = DataSerializer.readString(in);
    if (vmKind == DistributionManager.LONER_DM_TYPE) {
        this.uniqueTag = DataSerializer.readString(in);
    } else {
        String str = DataSerializer.readString(in);
        if (str != null) {
            // backward compatibility from earlier than 6.5
            vmViewId = Integer.parseInt(str);
        }
    }
    String durableId = DataSerializer.readString(in);
    int durableTimeout = DataSerializer.readInteger(in).intValue();
    DurableClientAttributes durableClientAttributes = durableId.length() > 0 ? new DurableClientAttributes(durableId, durableTimeout) : null;
    short version = readVersion(flags, in);
    MemberAttributes attr = new MemberAttributes(dcPort, vmPid, vmKind, vmViewId, name, groups, durableClientAttributes);
    netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord, version, attr);
    Assert.assertTrue(netMbr.getVmKind() > 0);
}
Also used : InetAddress(java.net.InetAddress) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Example 8 with DurableClientAttributes

use of org.apache.geode.distributed.DurableClientAttributes in project geode by apache.

the class InternalDistributedMember method fromDataPre_GFE_9_0_0_0.

public void fromDataPre_GFE_9_0_0_0(DataInput in) throws IOException, ClassNotFoundException {
    InetAddress inetAddr = DataSerializer.readInetAddress(in);
    int port = in.readInt();
    this.hostName = DataSerializer.readString(in);
    this.hostName = SocketCreator.resolve_dns ? SocketCreator.getCanonicalHostName(inetAddr, hostName) : inetAddr.getHostAddress();
    int flags = in.readUnsignedByte();
    boolean sbEnabled = (flags & NPD_ENABLED_BIT) != 0;
    boolean elCoord = (flags & COORD_ENABLED_BIT) != 0;
    this.isPartial = (flags & PARTIAL_ID_BIT) != 0;
    int dcPort = in.readInt();
    int vmPid = in.readInt();
    int vmKind = in.readUnsignedByte();
    String[] groups = DataSerializer.readStringArray(in);
    int vmViewId = -1;
    String name = DataSerializer.readString(in);
    if (vmKind == DistributionManager.LONER_DM_TYPE) {
        this.uniqueTag = DataSerializer.readString(in);
    } else {
        String str = DataSerializer.readString(in);
        if (str != null) {
            // backward compatibility from earlier than 6.5
            vmViewId = Integer.parseInt(str);
        }
    }
    String durableId = DataSerializer.readString(in);
    int durableTimeout = DataSerializer.readInteger(in).intValue();
    DurableClientAttributes durableClientAttributes = durableId.length() > 0 ? new DurableClientAttributes(durableId, durableTimeout) : null;
    short version = readVersion(flags, in);
    MemberAttributes attr = new MemberAttributes(dcPort, vmPid, vmKind, vmViewId, name, groups, durableClientAttributes);
    netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord, version, attr);
    Assert.assertTrue(netMbr.getVmKind() > 0);
// Assert.assertTrue(getPort() > 0);
}
Also used : InetAddress(java.net.InetAddress) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes)

Example 9 with DurableClientAttributes

use of org.apache.geode.distributed.DurableClientAttributes in project geode by apache.

the class LonerDistributionManager method generateMemberId.

// private static final int CHARS_32KB = 16384;
private InternalDistributedMember generateMemberId() {
    InternalDistributedMember result = null;
    String host;
    try {
        // create string of the current millisecond clock time
        StringBuffer sb = new StringBuffer();
        // use low four bytes for backward compatibility
        long time = System.currentTimeMillis() & 0xffffffffL;
        for (int i = 0; i < 4; i++) {
            String hex = Integer.toHexString((int) (time & 0xff));
            if (hex.length() < 2) {
                sb.append('0');
            }
            sb.append(hex);
            time = time / 0x100;
        }
        String uniqueString = sb.toString();
        String name = this.system.getName();
        InetAddress hostAddr = SocketCreator.getLocalHost();
        host = SocketCreator.use_client_host_name ? hostAddr.getCanonicalHostName() : hostAddr.getHostAddress();
        DistributionConfig config = system.getConfig();
        DurableClientAttributes dac = null;
        if (config.getDurableClientId() != null) {
            dac = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
        }
        result = new InternalDistributedMember(host, lonerPort, name, uniqueString, DistributionManager.LONER_DM_TYPE, MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dac);
    } catch (UnknownHostException ex) {
        throw new InternalGemFireError(LocalizedStrings.LonerDistributionManager_CANNOT_RESOLVE_LOCAL_HOST_NAME_TO_AN_IP_ADDRESS.toLocalizedString());
    }
    return result;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) DurableClientAttributes(org.apache.geode.distributed.DurableClientAttributes) InternalGemFireError(org.apache.geode.InternalGemFireError)

Aggregations

DurableClientAttributes (org.apache.geode.distributed.DurableClientAttributes)9 InetAddress (java.net.InetAddress)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 java.io (java.io)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 UnknownHostException (java.net.UnknownHostException)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)1 MemberAttributes (org.apache.geode.distributed.internal.membership.MemberAttributes)1 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)1 Event (org.jgroups.Event)1 UDP (org.jgroups.protocols.UDP)1 IpAddress (org.jgroups.stack.IpAddress)1 UUID (org.jgroups.util.UUID)1