use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class JGroupsMessenger method establishLocalAddress.
private void establishLocalAddress() {
UUID logicalAddress = (UUID) myChannel.getAddress();
logicalAddress = logicalAddress.copy();
IpAddress ipaddr = (IpAddress) myChannel.down(new Event(Event.GET_PHYSICAL_ADDRESS));
if (ipaddr != null) {
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} else {
UDP udp = (UDP) myChannel.getProtocolStack().getTransport();
try {
Method getAddress = UDP.class.getDeclaredMethod("getPhysicalAddress");
getAddress.setAccessible(true);
ipaddr = (IpAddress) getAddress.invoke(udp, new Object[0]);
this.jgAddress = new JGAddress(logicalAddress, ipaddr);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
logger.info("Unable to find getPhysicallAddress method in UDP - parsing its address instead");
}
// if (this.jgAddress == null) {
// String addr = udp.getLocalPhysicalAddress();
// int cidx = addr.lastIndexOf(':'); // IPv6 literals might have colons
// String host = addr.substring(0, cidx);
// int jgport = Integer.parseInt(addr.substring(cidx+1, addr.length()));
// try {
// this.jgAddress = new JGAddress(logicalAddress, new IpAddress(InetAddress.getByName(host),
// jgport));
// } catch (UnknownHostException e) {
// myChannel.disconnect();
// throw new SystemConnectException("unable to initialize jgroups address", e);
// }
// }
}
// install the address in the JGroups channel protocols
myChannel.down(new Event(Event.SET_LOCAL_ADDRESS, this.jgAddress));
DistributionConfig config = services.getConfig().getDistributionConfig();
boolean isLocator = (services.getConfig().getTransport().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty();
// establish the DistributedSystem's address
DurableClientAttributes dca = null;
if (config.getDurableClientId() != null) {
dca = new DurableClientAttributes(config.getDurableClientId(), config.getDurableClientTimeout());
}
MemberAttributes attr = new MemberAttributes(-1, /* dcPort - not known at this time */
OSProcess.getId(), services.getConfig().getTransport().getVmKind(), -1, /* view id - not known at this time */
config.getName(), MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dca);
localAddress = new InternalDistributedMember(jgAddress.getInetAddress(), jgAddress.getPort(), config.getEnableNetworkPartitionDetection(), isLocator, attr);
// add the JGroups logical address to the GMSMember
UUID uuid = this.jgAddress;
GMSMember gmsMember = (GMSMember) localAddress.getNetMember();
gmsMember.setUUID(uuid);
gmsMember.setMemberWeight((byte) (services.getConfig().getMemberWeight() & 0xff));
gmsMember.setNetworkPartitionDetectionEnabled(services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection());
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class GMSJoinLeave method init.
@Override
public void init(Services s) {
this.services = s;
DistributionConfig dc = services.getConfig().getDistributionConfig();
if (dc.getMcastPort() != 0 && StringUtils.isBlank(dc.getLocators()) && StringUtils.isBlank(dc.getStartLocator())) {
throw new GemFireConfigException("Multicast cannot be configured for a non-distributed cache." + " Please configure the locator services for this cache using " + LOCATORS + " or " + START_LOCATOR + ".");
}
services.getMessenger().addHandler(JoinRequestMessage.class, this);
services.getMessenger().addHandler(JoinResponseMessage.class, this);
services.getMessenger().addHandler(InstallViewMessage.class, this);
services.getMessenger().addHandler(ViewAckMessage.class, this);
services.getMessenger().addHandler(LeaveRequestMessage.class, this);
services.getMessenger().addHandler(RemoveMemberMessage.class, this);
services.getMessenger().addHandler(FindCoordinatorRequest.class, this);
services.getMessenger().addHandler(FindCoordinatorResponse.class, this);
services.getMessenger().addHandler(NetworkPartitionMessage.class, this);
int ackCollectionTimeout = dc.getMemberTimeout() * 2 * 12437 / 10000;
if (ackCollectionTimeout < 1500) {
ackCollectionTimeout = 1500;
} else if (ackCollectionTimeout > 12437) {
ackCollectionTimeout = 12437;
}
ackCollectionTimeout = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "VIEW_ACK_TIMEOUT", ackCollectionTimeout).intValue();
this.viewAckTimeout = ackCollectionTimeout;
this.quorumRequired = services.getConfig().getDistributionConfig().getEnableNetworkPartitionDetection();
DistributionConfig dconfig = services.getConfig().getDistributionConfig();
String bindAddr = dconfig.getBindAddress();
locators = GMSUtil.parseLocators(dconfig.getLocators(), bindAddr);
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class FindRestEnabledServersFunction method execute.
public void execute(FunctionContext context) {
try {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
DistributionConfig config = InternalDistributedSystem.getAnyInstance().getConfig();
String bindAddress = RestAgent.getBindAddressForHttpService(config);
final String protocolType = config.getHttpServiceSSLEnabled() ? "https" : "http";
if (cache.isRESTServiceRunning()) {
context.getResultSender().lastResult(protocolType + "://" + bindAddress + ":" + config.getHttpServicePort());
} else {
context.getResultSender().lastResult("");
}
} catch (CacheClosedException ex) {
context.getResultSender().lastResult("");
}
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class AcceptorImpl method calcBindHostName.
/**
* @param bindName the ip address or host name that this acceptor should bind to. If null or ""
* then calculate it.
* @return the ip address or host name this acceptor will listen on. An "" if all local addresses
* will be listened to.
*
* @since GemFire 5.7
*/
private static String calcBindHostName(Cache cache, String bindName) {
if (bindName != null && !bindName.equals("")) {
return bindName;
}
InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
DistributionConfig config = system.getConfig();
String hostName = null;
// Get the server-bind-address. If it is not null, use it.
// If it is null, get the bind-address. If it is not null, use it.
// Otherwise set default.
String serverBindAddress = config.getServerBindAddress();
if (serverBindAddress != null && serverBindAddress.length() > 0) {
hostName = serverBindAddress;
} else {
String bindAddress = config.getBindAddress();
if (bindAddress != null && bindAddress.length() > 0) {
hostName = bindAddress;
}
}
return hostName;
}
use of org.apache.geode.distributed.internal.DistributionConfig in project geode by apache.
the class Connection method sendOKHandshakeReply.
private void sendOKHandshakeReply() throws IOException, ConnectionException {
byte[] my_okHandshakeBytes = null;
ByteBuffer my_okHandshakeBuf = null;
if (this.isReceiver) {
DistributionConfig cfg = owner.getConduit().config;
ByteBuffer bb;
if (useNIO() && TCPConduit.useDirectBuffers) {
bb = ByteBuffer.allocateDirect(128);
} else {
bb = ByteBuffer.allocate(128);
}
// reserve first 4 bytes for packet length
bb.putInt(0);
bb.put((byte) NORMAL_MSG_TYPE);
bb.putShort(MsgIdGenerator.NO_MSG_ID);
bb.put(REPLY_CODE_OK_WITH_ASYNC_INFO);
bb.putInt(cfg.getAsyncDistributionTimeout());
bb.putInt(cfg.getAsyncQueueTimeout());
bb.putInt(cfg.getAsyncMaxQueueSize());
// write own product version
Version.writeOrdinal(bb, Version.CURRENT.ordinal(), true);
// now set the msg length into position 0
bb.putInt(0, calcHdrSize(bb.position() - MSG_HEADER_BYTES));
if (useNIO()) {
my_okHandshakeBuf = bb;
bb.flip();
} else {
my_okHandshakeBytes = new byte[bb.position()];
bb.flip();
bb.get(my_okHandshakeBytes);
}
} else {
my_okHandshakeBuf = okHandshakeBuf;
my_okHandshakeBytes = okHandshakeBytes;
}
if (useNIO()) {
assert my_okHandshakeBuf != null;
synchronized (my_okHandshakeBuf) {
my_okHandshakeBuf.position(0);
nioWriteFully(getSocket().getChannel(), my_okHandshakeBuf, false, null);
}
} else {
synchronized (outLock) {
assert my_okHandshakeBytes != null;
this.output.write(my_okHandshakeBytes, 0, my_okHandshakeBytes.length);
this.output.flush();
}
}
}
Aggregations