use of sun.misc.Signal in project jdk8u_jdk by JetBrains.
the class Terminator method setup.
/* Invocations of setup and teardown are already synchronized
* on the shutdown lock, so no further synchronization is needed here
*/
static void setup() {
if (handler != null)
return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
// System.exit()
try {
Signal.handle(new Signal("INT"), sh);
} catch (IllegalArgumentException e) {
}
try {
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
}
}
use of sun.misc.Signal in project jdepth by Crab2died.
the class SignalCatch method main.
public static void main(String... args) throws IOException {
SignalHandler handler = new SignalCatch();
handler.handle(new Signal("TERM"));
handler.handle(new Signal("SEGV"));
handler.handle(new Signal("ILL"));
handler.handle(new Signal("FPE"));
handler.handle(new Signal("ABRT"));
handler.handle(new Signal("INT"));
handler.handle(new Signal("BREAK"));
}
use of sun.misc.Signal in project evosuite by EvoSuite.
the class PropertiesNoveltySearchFactory method getSearchAlgorithm.
@Override
public // public GeneticAlgorithm<TestChromosome> getSearchAlgorithm() {
NoveltySearch<TestChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestChromosome> factory = getChromosomeFactory();
NoveltySearch<TestChromosome> ga = new NoveltySearch<>(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestChromosome> selectionFunction = getSelectionFunction();
selectionFunction.setMaximize(false);
ga.setSelectionFunction(selectionFunction);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Properties.Criterion.STRONGMUTATION)) {
if (Properties.STRATEGY == Properties.Strategy.ONEBRANCH)
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
else
ga.addListener(new MutationTestPool());
// } else if (Properties.CRITERION == Criterion.DEFUSE) {
// if (Properties.STRATEGY == Strategy.EVOSUITE)
// ga.addListener(new DefUseTestPool());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
// ga.addBloatControl(new MaxLengthBloatControl());
TestCaseSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
ga.addListener(map);
}
if (Properties.SHUTDOWN_HOOK) {
// ShutdownTestWriter writer = new
// ShutdownTestWriter(Thread.currentThread());
ShutdownTestWriter writer = new ShutdownTestWriter();
ga.addStoppingCondition(writer);
RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
ga.addStoppingCondition(rmi);
if (Properties.STOPPING_PORT != -1) {
SocketStoppingCondition ss = new SocketStoppingCondition();
ss.accept();
ga.addStoppingCondition(ss);
}
// Runtime.getRuntime().addShutdownHook(writer);
Signal.handle(new Signal("INT"), writer);
}
ga.addListener(new ResourceController());
return ga;
}
use of sun.misc.Signal in project evosuite by EvoSuite.
the class PropertiesSuiteGAFactory method getSearchAlgorithm.
@Override
public GeneticAlgorithm<TestSuiteChromosome> getSearchAlgorithm() {
ChromosomeFactory<TestSuiteChromosome> factory = getChromosomeFactory();
// FIXXME
GeneticAlgorithm<TestSuiteChromosome> ga = getGeneticAlgorithm(factory);
if (Properties.NEW_STATISTICS)
ga.addListener(new StatisticsListener());
// How to select candidates for reproduction
SelectionFunction<TestSuiteChromosome> selectionFunction = getSelectionFunction();
selectionFunction.setMaximize(false);
ga.setSelectionFunction(selectionFunction);
// When to stop the search
StoppingCondition stopping_condition = getStoppingCondition();
ga.setStoppingCondition(stopping_condition);
// ga.addListener(stopping_condition);
if (Properties.STOP_ZERO) {
ga.addStoppingCondition(new ZeroFitnessStoppingCondition());
}
if (!(stopping_condition instanceof MaxTimeStoppingCondition)) {
ga.addStoppingCondition(new GlobalTimeStoppingCondition());
}
if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION) || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
if (Properties.STRATEGY == Strategy.ONEBRANCH)
ga.addStoppingCondition(new MutationTimeoutStoppingCondition());
else
ga.addListener(new MutationTestPool());
// } else if (Properties.CRITERION == Criterion.DEFUSE) {
// if (Properties.STRATEGY == Strategy.EVOSUITE)
// ga.addListener(new DefUseTestPool());
}
ga.resetStoppingConditions();
ga.setPopulationLimit(getPopulationLimit());
// How to cross over
CrossOverFunction crossover_function = getCrossoverFunction();
ga.setCrossOverFunction(crossover_function);
if (Properties.CHECK_BEST_LENGTH) {
RelativeSuiteLengthBloatControl bloat_control = new org.evosuite.testsuite.RelativeSuiteLengthBloatControl();
ga.addBloatControl(bloat_control);
ga.addListener(bloat_control);
}
// ga.addBloatControl(new MaxLengthBloatControl());
TestSuiteSecondaryObjective.setSecondaryObjectives();
if (Properties.DYNAMIC_LIMIT) {
// max_s = GAProperties.generations * getBranches().size();
// TODO: might want to make this dependent on the selected coverage
// criterion
// TODO also, question: is branchMap.size() really intended here?
// I think BranchPool.getBranchCount() was intended
Properties.SEARCH_BUDGET = Properties.SEARCH_BUDGET * (BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getNumBranchlessMethods(Properties.TARGET_CLASS) + BranchPool.getInstance(TestGenerationContext.getInstance().getClassLoaderForSUT()).getBranchCountForClass(Properties.TARGET_CLASS) * 2);
stopping_condition.setLimit(Properties.SEARCH_BUDGET);
logger.info("Setting dynamic length limit to " + Properties.SEARCH_BUDGET);
}
if (Properties.LOCAL_SEARCH_RESTORE_COVERAGE) {
org.evosuite.ga.metaheuristics.SearchListener map = BranchCoverageMap.getInstance();
ga.addListener(map);
}
if (Properties.SHUTDOWN_HOOK) {
// ShutdownTestWriter writer = new
// ShutdownTestWriter(Thread.currentThread());
ShutdownTestWriter writer = new ShutdownTestWriter();
ga.addStoppingCondition(writer);
RMIStoppingCondition rmi = RMIStoppingCondition.getInstance();
ga.addStoppingCondition(rmi);
if (Properties.STOPPING_PORT != -1) {
SocketStoppingCondition ss = new SocketStoppingCondition();
ss.accept();
ga.addStoppingCondition(ss);
}
// Runtime.getRuntime().addShutdownHook(writer);
Signal.handle(new Signal("INT"), writer);
}
ga.addListener(new ResourceController());
return ga;
}
use of sun.misc.Signal in project orientdb by orientechnologies.
the class OHazelcastPlugin method startup.
@Override
public void startup() {
if (!enabled)
return;
Orient.instance().setRunningDistributed(true);
OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(Integer.MAX_VALUE);
OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(Integer.MAX_VALUE);
OGlobalConfiguration.STORAGE_TRACK_CHANGED_RECORDS_IN_WAL.setValue(true);
// REGISTER TEMPORARY USER FOR REPLICATION PURPOSE
serverInstance.addTemporaryUser(REPLICATOR_USER, "" + new SecureRandom().nextLong(), "*");
super.startup();
status = NODE_STATUS.STARTING;
final String localNodeName = nodeName;
activeNodes.clear();
activeNodesNamesByUuid.clear();
activeNodesUuidByName.clear();
// CLOSE ALL CONNECTIONS TO THE SERVERS
for (ORemoteServerController server : remoteServers.values()) server.close();
remoteServers.clear();
registeredNodeById.clear();
registeredNodeByName.clear();
try {
hazelcastInstance = configureHazelcast();
nodeUuid = hazelcastInstance.getCluster().getLocalMember().getUuid();
final LifecycleService lifecycleService = hazelcastInstance.getLifecycleService();
lifecycleService.addLifecycleListener(this);
OLogManager.instance().info(this, "Starting distributed server '%s' (hzID=%s)...", localNodeName, nodeUuid);
final long clusterTime = getClusterTime();
final long deltaTime = System.currentTimeMillis() - clusterTime;
OLogManager.instance().info(this, "Distributed cluster time=%s (delta from local node=%d)...", new Date(clusterTime), deltaTime);
activeNodes.put(localNodeName, hazelcastInstance.getCluster().getLocalMember());
activeNodesNamesByUuid.put(nodeUuid, localNodeName);
activeNodesUuidByName.put(localNodeName, nodeUuid);
configurationMap = new OHazelcastDistributedMap(this, hazelcastInstance);
OServer.registerServerInstance(localNodeName, serverInstance);
initRegisteredNodeIds();
// PUBLISH CURRENT NODE NAME
final ODocument nodeCfg = new ODocument();
nodeCfg.setTrackingChanges(false);
// REMOVE ANY PREVIOUS REGISTERED SERVER WITH THE SAME NODE NAME
final Set<String> node2Remove = new HashSet<String>();
for (Iterator<Map.Entry<String, Object>> it = configurationMap.getHazelcastMap().entrySet().iterator(); it.hasNext(); ) {
final Map.Entry<String, Object> entry = it.next();
if (entry.getKey().startsWith(CONFIG_NODE_PREFIX)) {
final ODocument nCfg = (ODocument) entry.getValue();
if (nodeName.equals(nCfg.field("name"))) {
// SAME NODE NAME: REMOVE IT
node2Remove.add(entry.getKey());
}
}
}
for (String n : node2Remove) configurationMap.getHazelcastMap().remove(n);
nodeCfg.field("id", nodeId);
nodeCfg.field("uuid", nodeUuid);
nodeCfg.field("name", nodeName);
ORecordInternal.setRecordSerializer(nodeCfg, ODatabaseDocumentTx.getDefaultSerializer());
configurationMap.put(CONFIG_NODE_PREFIX + nodeUuid, nodeCfg);
// REGISTER CURRENT NODES
for (Member m : hazelcastInstance.getCluster().getMembers()) {
if (!m.getUuid().equals(nodeUuid)) {
boolean found = false;
for (int retry = 0; retry < 10; ++retry) {
final String memberName = getNodeName(m, false);
if (memberName == null || memberName.startsWith("ext:")) {
// ACTIVE NODE IN HZ, BUT NOT YET REGISTERED, WAIT AND RETRY
Thread.sleep(1000);
continue;
}
found = true;
activeNodes.put(memberName, m);
activeNodesNamesByUuid.put(m.getUuid(), memberName);
activeNodesUuidByName.put(memberName, m.getUuid());
break;
}
if (!found)
ODistributedServerLog.warn(this, localNodeName, null, DIRECTION.NONE, "Cannot find configuration for member: %s, uuid", m, m.getUuid());
}
}
assignLockManagerFromCluster();
messageService = new ODistributedMessageServiceImpl(this);
initSystemDatabase();
ODistributedServerLog.info(this, localNodeName, null, DIRECTION.NONE, "Servers in cluster: %s", activeNodes.keySet());
publishLocalNodeConfiguration();
if (!configurationMap.containsKey(CONFIG_NODE_PREFIX + nodeUuid)) {
// NODE NOT REGISTERED, FORCING SHUTTING DOWN
ODistributedServerLog.error(this, localNodeName, null, DIRECTION.NONE, "Error on registering local node on cluster");
throw new ODistributedStartupException("Error on registering local node on cluster");
}
// CONNECTS TO ALL THE AVAILABLE NODES
for (String m : activeNodes.keySet()) if (!m.equals(nodeName))
getRemoteServer(m);
publishLocalNodeConfiguration();
installNewDatabasesFromCluster();
loadLocalDatabases();
membershipListenerMapRegistration = configurationMap.getHazelcastMap().addEntryListener(this, true);
membershipListenerRegistration = hazelcastInstance.getCluster().addMembershipListener(this);
// REGISTER CURRENT MEMBERS
setNodeStatus(NODE_STATUS.ONLINE);
publishLocalNodeConfiguration();
final long delay = OGlobalConfiguration.DISTRIBUTED_PUBLISH_NODE_STATUS_EVERY.getValueAsLong();
if (delay > 0) {
publishLocalNodeConfigurationTask = new TimerTask() {
@Override
public void run() {
publishLocalNodeConfiguration();
}
};
Orient.instance().scheduleTask(publishLocalNodeConfigurationTask, delay, delay);
}
final long statsDelay = OGlobalConfiguration.DISTRIBUTED_DUMP_STATS_EVERY.getValueAsLong();
if (statsDelay > 0) {
haStatsTask = new TimerTask() {
@Override
public void run() {
dumpStats();
}
};
Orient.instance().scheduleTask(haStatsTask, statsDelay, statsDelay);
}
final long healthChecker = OGlobalConfiguration.DISTRIBUTED_CHECK_HEALTH_EVERY.getValueAsLong();
if (healthChecker > 0) {
healthCheckerTask = new OClusterHealthChecker(this);
Orient.instance().scheduleTask(healthCheckerTask, healthChecker, healthChecker);
}
for (OServerNetworkListener nl : serverInstance.getNetworkListeners()) nl.registerBeforeConnectNetworkEventListener(this);
// WAIT ALL THE MESSAGES IN QUEUE ARE PROCESSED OR MAX 10 SECONDS
waitStartupIsCompleted();
signalListener = new OSignalHandler.OSignalListener() {
@Override
public void onSignal(final Signal signal) {
if (signal.toString().trim().equalsIgnoreCase("SIGTRAP"))
dumpStats();
}
};
Orient.instance().getSignalHandler().registerListener(signalListener);
} catch (Exception e) {
ODistributedServerLog.error(this, localNodeName, null, DIRECTION.NONE, "Error on starting distributed plugin", e);
throw OException.wrapException(new ODistributedStartupException("Error on starting distributed plugin"), e);
}
dumpServersStatus();
}
Aggregations