本文整理汇总了Java中com.hazelcast.nio.Address类的典型用法代码示例。如果您正苦于以下问题:Java Address类的具体用法?Java Address怎么用?Java Address使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Address类属于com.hazelcast.nio包,在下文中一共展示了Address类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineMyLocalAddress
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Override
@SneakyThrows
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
Object usePublicAddress = registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
if (usePublicAddress instanceof Boolean && Boolean.class.cast(usePublicAddress)) {
log.info("Registrator config property: {}:{} attempting to use it...",
CONFIG_PROP_PREFER_PUBLIC_ADDRESS,
usePublicAddress);
Address publicAddress = localDiscoveryNode.getPublicAddress();
myLocalAddress = (publicAddress != null) ? publicAddress : myLocalAddress;
}
return new Address(INET_UTILS_INSTANCE.findFirstNonLoopbackHostInfo().getIpAddress(), myLocalAddress.getPort());
}
示例2: determineMyLocalAddress
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Override
@SneakyThrows
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) {
logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it...");
Address publicAddress = localDiscoveryNode.getPublicAddress();
if (publicAddress != null) {
myLocalAddress = publicAddress;
}
}
return new Address(InetUtils.getFirstNonLoopbackHostInfo().getIpAddress(), myLocalAddress.getPort());
}
示例3: discoveryProviderTest
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Test
public void discoveryProviderTest() throws Exception {
environmentVariables.set("HEROKU_DNS_FORMATION_NAME", "localhost");
DiscoveryNode local = new SimpleDiscoveryNode(new Address("127.0.0.1", 1010));
DiscoveryStrategyFactory factory = new HerokuDiscoveryStrategyFactory();
DiscoveryStrategy provider = factory.newDiscoveryStrategy(local, null, new HashMap<>());
provider.start();
Iterable<DiscoveryNode> nodes = provider.discoverNodes();
Assert.assertNotNull(nodes);
Assert.assertTrue("Empty DiscoveryNode list", nodes.iterator().hasNext());
for (DiscoveryNode node : nodes) {
LOGGER.info("Node -> {}", node.getPublicAddress());
}
}
示例4: setup
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Before
public void setup()
throws UnknownHostException {
for (int i = 0; i < NUMBER_OF_NODES; i++) {
HashSet<String> privateAddresses = new HashSet<String>();
privateAddresses.add("127.0.0." + (i + 1));
NodeMetadata.Status status = NodeMetadata.Status.PENDING;
if (i < NUMBER_OF_RUNNING_NODES) {
status = NodeMetadata.Status.RUNNING;
addressesOfRunningInstances.add(new Address(privateAddresses.iterator().next(), 0));
}
nodes.add(new NodeMetadataImpl("", "", "dummyId" + i,
null,
null,
new HashMap<String, String>(),
new HashSet<String>(),
null, null, null, null,
status, "",
STARTING_PORT + i, privateAddresses, privateAddresses, null, "dummyHostName" + i));
}
}
示例5: determineMyLocalAddress
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Override
public Address determineMyLocalAddress(DiscoveryNode localDiscoveryNode, Map<String, Object> registratorConfig) {
Address myLocalAddress = localDiscoveryNode.getPrivateAddress();
Object usePublicAddress = (Object)registratorConfig.get(CONFIG_PROP_PREFER_PUBLIC_ADDRESS);
if (usePublicAddress != null && usePublicAddress instanceof Boolean && (Boolean)usePublicAddress) {
logger.info("Registrator config property: " + CONFIG_PROP_PREFER_PUBLIC_ADDRESS +":"+usePublicAddress + " attempting to use it...");
Address publicAddress = localDiscoveryNode.getPublicAddress();
if (publicAddress != null) {
myLocalAddress = publicAddress;
}
}
return myLocalAddress;
}
开发者ID:bitsofinfo,项目名称:hazelcast-consul-discovery-spi,代码行数:17,代码来源:LocalDiscoveryNodeRegistrator.java
示例6: buildRegistrationCheck
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Override
public RegCheck buildRegistrationCheck(Map<String, Object> registratorConfig, Address localAddress) {
RegCheck regCheck = null;
try {
/**
* Deal with health check tcp
*/
String healthCheckTcp = (String)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP);
if (healthCheckTcp != null && !healthCheckTcp.trim().isEmpty()) {
healthCheckTcp = healthCheckTcp.replaceAll(TCP_TEMPLATE_MYIP, localAddress.getInetAddress().getHostAddress())
.replaceAll(TCP_TEMPLATE_MYPORT, String.valueOf(localAddress.getPort()));
Long healthCheckTcpIntervalSeconds = Long.valueOf((Integer)registratorConfig.get(CONFIG_PROP_HEALTH_CHECK_TCP_INTERVAL_SECONDS));
regCheck = Registration.RegCheck.tcp(healthCheckTcp, healthCheckTcpIntervalSeconds);
}
} catch(Exception e) {
logger.severe("Unexpected error occured trying to build TCP health check : " + e.getMessage(), e);
}
return regCheck;
}
示例7: createFlowControlPacket
import com.hazelcast.nio.Address; //导入依赖的package包/类
private byte[] createFlowControlPacket(Address member) throws IOException {
final ObjectDataOutput out = createObjectDataOutput(nodeEngine);
final boolean[] hasData = {false};
Map<Long, ExecutionContext> executionContexts = jobExecutionService.getExecutionContexts();
out.writeInt(executionContexts.size());
executionContexts.forEach((execId, exeCtx) -> uncheckRun(() -> {
if (!exeCtx.hasParticipant(member)) {
return;
}
out.writeLong(execId);
out.writeInt(exeCtx.receiverMap().values().stream().mapToInt(Map::size).sum());
exeCtx.receiverMap().forEach((vertexId, ordinalToSenderToTasklet) ->
ordinalToSenderToTasklet.forEach((ordinal, senderToTasklet) -> uncheckRun(() -> {
out.writeInt(vertexId);
out.writeInt(ordinal);
out.writeInt(senderToTasklet.get(member).updateAndGetSendSeqLimitCompressed());
hasData[0] = true;
})));
}));
return hasData[0] ? out.toByteArray() : EMPTY_BYTES;
}
示例8: doRun
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Override
protected void doRun() throws Exception {
ExecutionContext execCtx = getExecutionCtx();
Address coordinator = getCallerAddress();
getLogger().info("Start execution of "
+ jobAndExecutionId(jobId(), executionId) + " from coordinator " + coordinator);
execCtx.beginExecution().whenComplete(withTryCatch(getLogger(), (i, e) -> {
if (e != null) {
getLogger().fine("Execution of " + jobAndExecutionId(jobId(), executionId)
+ " completed with failure", e);
} else {
getLogger().fine("Execution of " + jobAndExecutionId(jobId(), executionId) + " completed");
}
doSendResponse(e);
}));
}
示例9: memberToSenderConveyorMap
import com.hazelcast.nio.Address; //导入依赖的package包/类
/**
* Creates (if absent) for the given edge one sender tasklet per remote member,
* each with a single conveyor with a number of producer queues feeding it.
* Populates the {@link #senderMap} and {@link #tasklets} fields.
*/
private Map<Address, ConcurrentConveyor<Object>> memberToSenderConveyorMap(
Map<String, Map<Address, ConcurrentConveyor<Object>>> edgeSenderConveyorMap, EdgeDef edge
) {
assert edge.isDistributed() : "Edge is not distributed";
return edgeSenderConveyorMap.computeIfAbsent(edge.edgeId(), x -> {
final Map<Address, ConcurrentConveyor<Object>> addrToConveyor = new HashMap<>();
for (Address destAddr : remoteMembers.get()) {
final ConcurrentConveyor<Object> conveyor = createConveyorArray(
1, edge.sourceVertex().parallelism(), edge.getConfig().getQueueSize())[0];
final ConcurrentInboundEdgeStream inboundEdgeStream = newEdgeStream(edge, conveyor);
final int destVertexId = edge.destVertex().vertexId();
final SenderTasklet t = new SenderTasklet(inboundEdgeStream, nodeEngine,
destAddr, executionId, destVertexId, edge.getConfig().getPacketSizeLimit());
senderMap.computeIfAbsent(destVertexId, xx -> new HashMap<>())
.computeIfAbsent(edge.destOrdinal(), xx -> new HashMap<>())
.put(destAddr, t);
tasklets.add(t);
addrToConveyor.put(destAddr, conveyor);
}
return addrToConveyor;
});
}
示例10: createIfAbsentReceiverTasklet
import com.hazelcast.nio.Address; //导入依赖的package包/类
private void createIfAbsentReceiverTasklet(EdgeDef edge, int[][] ptionsPerProcessor, int totalPtionCount) {
final ConcurrentConveyor<Object>[] localConveyors = localConveyorMap.get(edge.edgeId());
receiverMap.computeIfAbsent(edge.destVertex().vertexId(), x -> new HashMap<>())
.computeIfAbsent(edge.destOrdinal(), x -> {
Map<Address, ReceiverTasklet> addrToTasklet = new HashMap<>();
//create a receiver per address
int offset = 0;
for (Address addr : ptionArrgmt.remotePartitionAssignment.get().keySet()) {
final OutboundCollector[] collectors = new OutboundCollector[ptionsPerProcessor.length];
// assign the queues starting from end
final int queueOffset = --offset;
Arrays.setAll(collectors, n -> new ConveyorCollector(
localConveyors[n], localConveyors[n].queueCount() + queueOffset,
ptionsPerProcessor[n]));
final OutboundCollector collector = compositeCollector(collectors, edge, totalPtionCount);
ReceiverTasklet receiverTasklet = new ReceiverTasklet(
collector, edge.getConfig().getReceiveWindowMultiplier(),
getConfig().getInstanceConfig().getFlowControlPeriodMs());
addrToTasklet.put(addr, receiverTasklet);
}
return addrToTasklet;
});
}
示例11: initPartitionOwnersAndMembers
import com.hazelcast.nio.Address; //导入依赖的package包/类
private static void initPartitionOwnersAndMembers(NodeEngine nodeEngine,
MembersView membersView,
Collection<MemberInfo> members,
Address[] partitionOwners) {
IPartitionService partitionService = nodeEngine.getPartitionService();
for (int partitionId = 0; partitionId < partitionOwners.length; partitionId++) {
Address address = partitionService.getPartitionOwnerOrWait(partitionId);
MemberInfo member;
if ((member = membersView.getMember(address)) == null) {
// Address in partition table doesn't exist in member list,
// it has just left the cluster.
throw new TopologyChangedException("Topology changed, " + address + " is not in original member list");
}
// add member to known members
members.add(member);
partitionOwners[partitionId] = address;
}
}
示例12: opForMember
import com.hazelcast.nio.Address; //导入依赖的package包/类
private PartitionOpBuilder opForMember(Address member, List<Integer> partitions, MapEntries[] partitionToEntries) {
PartitionOpBuilder builder = new PartitionOpBuilder(member);
builder.entries = new MapEntries[partitions.size()];
builder.partitions = new int[partitions.size()];
int index = 0;
for (Integer partition : partitions) {
if (partitionToEntries[partition] != null) {
builder.entries[index] = partitionToEntries[partition];
builder.partitions[index] = partition;
index++;
}
}
if (index == 0) {
// no entries for this member, skip the member
return null;
}
// trim arrays to real sizes
if (index < partitions.size()) {
builder.entries = Arrays.copyOf(builder.entries, index);
builder.partitions = Arrays.copyOf(builder.partitions, index);
}
return builder;
}
示例13: testBackpressure
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Test
public void testBackpressure() throws Exception {
DAG dag = new DAG();
final int member1Port = jet1.getCluster().getLocalMember().getAddress().getPort();
final Member member2 = jet2.getCluster().getLocalMember();
final int ptionOwnedByMember2 =
jet1.getHazelcastInstance().getPartitionService()
.getPartitions().stream()
.filter(p -> p.getOwner().equals(member2))
.map(Partition::getPartitionId)
.findAny()
.orElseThrow(() -> new RuntimeException("Can't find a partition owned by member " + jet2));
Vertex source = dag.newVertex("source", ProcessorMetaSupplier.of((Address address) ->
ProcessorSupplier.of(address.getPort() == member1Port ? GenerateP::new : noopP())
));
Vertex hiccup = dag.newVertex("hiccup", HiccupP::new);
Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
dag.edge(between(source, hiccup)
.distributed().partitioned(wholeItem(), (x, y) -> ptionOwnedByMember2))
.edge(between(hiccup, sink));
jet1.newJob(dag).join();
assertCounts(jet1.getMap("counts"));
}
示例14: testPopulate
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Test
public void testPopulate() throws UnknownHostException {
r.register(createOperation("1.2.3.4", 1234, 2223L));
r.register(createOperation("1.2.3.4", 1234, 2222L));
r.register(createOperation("1.2.3.3", 1234, 2222L));
CallsPerMember liveOperations = new CallsPerMember(new Address("1.2.3.3", 1234));
r.populate(liveOperations);
Set<Address> addresses = liveOperations.addresses();
assertEquals(addresses.size(), 2);
assertTrue(addresses.contains(new Address("1.2.3.4", 1234)));
assertTrue(addresses.contains(new Address("1.2.3.3", 1234)));
long[] runningOperations = liveOperations.toOpControl(new Address("1.2.3.4", 1234)).runningOperations();
assertTrue(Arrays.equals(new long[] { 2222, 2223}, runningOperations)
|| Arrays.equals(new long[] { 2223, 2222 }, runningOperations));
runningOperations = liveOperations.toOpControl(new Address("1.2.3.3", 1234)).runningOperations();
assertArrayEquals(new long[] { 2222 }, runningOperations);
//callIds.
}
示例15: when_exceptionInProcessorSupplierOnOtherNode_then_failJob
import com.hazelcast.nio.Address; //导入依赖的package包/类
@Test
public void when_exceptionInProcessorSupplierOnOtherNode_then_failJob() throws Throwable {
factory.newMember();
instance = factory.newMember();
// Given
RuntimeException e = new RuntimeException("mock error");
final int localPort = instance.getCluster().getLocalMember().getAddress().getPort();
DAG dag = new DAG().vertex(new Vertex("faulty",
ProcessorMetaSupplier.of(
(Address address) -> ProcessorSupplier.of(
address.getPort() == localPort ? noopP() : () -> {
throw e;
})
)));
// Then
expectedException.expect(e.getClass());
expectedException.expectMessage(e.getMessage());
// When
executeAndPeel(instance.newJob(dag));
}