CNamespaceAddress

The namespace address is the address of a namespace. It consists of a node address to identify the node and a namespace ID. In string form, the address is structured like this: "nid.nodeId.segmentId".

 

IDs and addresses

Constructors

The default constructor creates an invalid address.

final CNamespaceAddress a = new CNamespaceAddress();

There is a constructor that takes a namespace ID and creates a local address. The node address remains empty. Empty or invalid node addresses are considered local addresses.

final IId namespaceId = CIdFactory.fromObject("TEST");
final CNamespaceAddress a = new CNamespaceAddress(namespaceId);

Another constructor takes a namespace ID and a node address.

final IId namespaceId = CIdFactory.fromObject("TEST");
final CNodeAddress nodeAddress = CNodeAddress.fromString("NODE1.SEG1");
final CNamespaceAddress a = new CNamespaceAddress(namespaceId,
                                                  nodeAddress);

Finally, you can also pass all three components of the address:

final IId namespaceId = CIdFactory.fromObject("TEST");
final CNodeId nodeId = CNodeId.fromObject("NODE1");
final CSegmentId segmentId = CSegmentId.fromObject("SEG1");
final CNamespaceAddress address = new CNamespaceAddress(namespaceId,
                                                        nodeId,
                                                        segmentId);

A random address for tests fetches this static method:

@NotNull
public static CNamespaceAddress random();

Getter

There are the following getters:

public @NotNull IId getNID();
public @NotNull CNodeId getNodeId();
public @NotNull CSegmentId getSegmentId();
public @NotNull CNodeAddress getNodeAddress();

Stream I/O

This static method reads a node address from a DataInput stream:

@Nullable
public static CNamespaceAddress fromStream(@NotNull final DataInput aStream) throws IOException;

Another static method writes a namespace address to a DataOutput stream:

public static void toStream(@NotNull final DataOutput aStream,
                            @Nullable final CNamespaceAddress aValue) throws IOException;

String I/O

This static method reads a namespace address from a string:

@NotNull
public static CNamespaceAddress fromString(@Nullable final String aString);

This method creates a string from which the namespace address can also be read out again:

@NotNull
public String valueToString();

Comparison

The following comparison methods are offered:

public boolean match(@Nullable final IId aNID,
                     @Nullable final CNodeAddress aNodeAddress);
public boolean matchNid(@Nullable final IId aNID);

Notice

CNamespaceAddress supports the equals and hashCode methods as well as the Comparable interface.

nyssr.net - Innovative Distributed System