use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.
the class JGroupsMessenger method init.
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void init(Services s) {
this.services = s;
RemoteTransportConfig transport = services.getConfig().getTransport();
DistributionConfig dc = services.getConfig().getDistributionConfig();
boolean b = dc.getEnableNetworkPartitionDetection();
System.setProperty("jgroups.resolve_dns", String.valueOf(!b));
InputStream is;
String r;
if (transport.isMcastEnabled()) {
r = JGROUPS_MCAST_CONFIG_FILE_NAME;
} else {
r = DEFAULT_JGROUPS_TCP_CONFIG;
}
is = ClassPathLoader.getLatest().getResourceAsStream(getClass(), r);
if (is == null) {
throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_CANNOT_FIND_0.toLocalizedString(r));
}
String properties;
try {
// PlainConfigurator config = PlainConfigurator.getInstance(is);
// properties = config.getProtocolStackString();
StringBuilder sb = new StringBuilder(3000);
BufferedReader br;
br = new BufferedReader(new InputStreamReader(is, "US-ASCII"));
String input;
while ((input = br.readLine()) != null) {
sb.append(input);
}
br.close();
properties = sb.toString();
} catch (Exception ex) {
throw new GemFireConfigException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_READING_JGROUPS_CONFIG.toLocalizedString(), ex);
}
if (properties.startsWith("<!--")) {
int commentEnd = properties.indexOf("-->");
properties = properties.substring(commentEnd + 3);
}
if (transport.isMcastEnabled()) {
properties = replaceStrings(properties, "MCAST_PORT", String.valueOf(transport.getMcastId().getPort()));
properties = replaceStrings(properties, "MCAST_ADDRESS", dc.getMcastAddress().getHostAddress());
properties = replaceStrings(properties, "MCAST_TTL", String.valueOf(dc.getMcastTtl()));
properties = replaceStrings(properties, "MCAST_SEND_BUFFER_SIZE", String.valueOf(dc.getMcastSendBufferSize()));
properties = replaceStrings(properties, "MCAST_RECV_BUFFER_SIZE", String.valueOf(dc.getMcastRecvBufferSize()));
properties = replaceStrings(properties, "MCAST_RETRANSMIT_INTERVAL", "" + Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "mcast-retransmit-interval", 500));
properties = replaceStrings(properties, "RETRANSMIT_LIMIT", String.valueOf(dc.getUdpFragmentSize() - 256));
}
if (transport.isMcastEnabled() || transport.isTcpDisabled() || (dc.getUdpRecvBufferSize() != DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE)) {
properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + dc.getUdpRecvBufferSize());
} else {
properties = replaceStrings(properties, "UDP_RECV_BUFFER_SIZE", "" + DistributionConfig.DEFAULT_UDP_RECV_BUFFER_SIZE_REDUCED);
}
properties = replaceStrings(properties, "UDP_SEND_BUFFER_SIZE", "" + dc.getUdpSendBufferSize());
String str = transport.getBindAddress();
// JGroups UDP protocol requires a bind address
if (str == null || str.length() == 0) {
try {
str = SocketCreator.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
throw new GemFireConfigException(e.getMessage(), e);
}
}
properties = replaceStrings(properties, "BIND_ADDR_SETTING", "bind_addr=\"" + str + "\"");
int port = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "jg-bind-port", 0);
if (port != 0) {
properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + port);
properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + 0);
} else {
int[] ports = dc.getMembershipPortRange();
properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE_START", "" + ports[0]);
properties = replaceStrings(properties, "MEMBERSHIP_PORT_RANGE", "" + (ports[1] - ports[0]));
}
properties = replaceStrings(properties, "UDP_FRAGMENT_SIZE", "" + dc.getUdpFragmentSize());
properties = replaceStrings(properties, "FC_MAX_CREDITS", "" + dc.getMcastFlowControl().getByteAllowance());
properties = replaceStrings(properties, "FC_THRESHOLD", "" + dc.getMcastFlowControl().getRechargeThreshold());
properties = replaceStrings(properties, "FC_MAX_BLOCK", "" + dc.getMcastFlowControl().getRechargeBlockMs());
this.jgStackConfig = properties;
if (!dc.getSecurityUDPDHAlgo().isEmpty()) {
try {
this.encrypt = new GMSEncrypt(services);
logger.info("Initializing GMSEncrypt ");
} catch (Exception e) {
throw new GemFireConfigException("problem initializing encryption protocol", e);
}
}
}
use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.
the class GMSMembershipManager method init.
@Override
public void init(Services services) {
this.services = services;
Assert.assertTrue(services != null);
DistributionConfig config = services.getConfig().getDistributionConfig();
RemoteTransportConfig transport = services.getConfig().getTransport();
this.membershipCheckTimeout = config.getSecurityPeerMembershipTimeout();
this.wasReconnectingSystem = transport.getIsReconnectingDS();
// cache these settings for use in send()
this.mcastEnabled = transport.isMcastEnabled();
this.tcpDisabled = transport.isTcpDisabled();
if (!this.tcpDisabled) {
dcReceiver = new MyDCReceiver(listener);
}
surpriseMemberTimeout = Math.max(20 * DistributionConfig.DEFAULT_MEMBER_TIMEOUT, 20 * config.getMemberTimeout());
surpriseMemberTimeout = Integer.getInteger(DistributionConfig.GEMFIRE_PREFIX + "surprise-member-timeout", surpriseMemberTimeout).intValue();
}
use of org.apache.geode.internal.admin.remote.RemoteTransportConfig in project geode by apache.
the class GMSLocatorRecoveryJUnitTest method testRecoverFromOther.
@Test
public void testRecoverFromOther() throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
// this locator will hook itself up with the first MembershipManager
// to be created
// l = Locator.startLocator(port, new File(""), localHost);
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(LOCATORS, localHost.getHostAddress() + '[' + port + ']');
nonDefault.put(BIND_ADDRESS, localHost.getHostAddress());
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
// start the first membership manager
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
// hook up the locator to the membership manager
((InternalLocator) l).getLocatorHandler().setMembershipManager(m1);
GMSLocator l2 = new GMSLocator(SocketCreator.getLocalHost(), new File("l2.dat"), m1.getLocalMember().getHost() + "[" + port + "]", true, true, new LocatorStats(), "");
l2.init(null);
assertTrue("expected view to contain " + m1.getLocalMember() + ": " + l2.getMembers(), l2.getMembers().contains(m1.getLocalMember()));
} finally {
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
Aggregations