本文整理汇总了Java中org.apache.ignite.internal.util.typedef.internal.U.sleep方法的典型用法代码示例。如果您正苦于以下问题:Java U.sleep方法的具体用法?Java U.sleep怎么用?Java U.sleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ignite.internal.util.typedef.internal.U
的用法示例。
在下文中一共展示了U.sleep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public void run() {
try {
while (!stop) {
try {
U.sleep(10);
}
catch (IgniteInterruptedCheckedException e) {
// No-op.
}
}
}
finally {
U.closeQuiet(srv);
}
}
示例2: retryAssert
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Tries few times to perform some assertion. In the worst case
* {@code assertion} closure will be executed {@code retries} + 1 times and
* thread will spend approximately {@code retries} * {@code retryInterval} sleeping.
*
* @param log Log.
* @param retries Number of retries.
* @param retryInterval Interval between retries in milliseconds.
* @param c Closure with assertion. All {@link AssertionError}s thrown
* from this closure will be ignored {@code retries} times.
* @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If interrupted.
*/
@SuppressWarnings("ErrorNotRethrown")
public static void retryAssert(@Nullable IgniteLogger log, int retries, long retryInterval, GridAbsClosure c)
throws IgniteInterruptedCheckedException {
for (int i = 0; i < retries; i++) {
try {
c.apply();
return;
}
catch (AssertionError e) {
U.warn(log, "Check failed (will retry in " + retryInterval + "ms).", e);
U.sleep(retryInterval);
}
}
// Apply the last time without guarding try.
c.apply();
}
示例3: checkEmpty
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Checks that cache is empty.
*
* @param cache Cache to check.
* @throws org.apache.ignite.internal.IgniteInterruptedCheckedException If interrupted while sleeping.
*/
@SuppressWarnings({"ErrorNotRethrown", "TypeMayBeWeakened"})
private void checkEmpty(IgniteCache<String, String> cache) throws IgniteInterruptedCheckedException {
for (int i = 0; i < 3; i++) {
try {
assertTrue(!cache.iterator().hasNext());
break;
}
catch (AssertionError e) {
if (i == 2)
throw e;
info(">>> Cache is not empty, flushing evictions.");
U.sleep(1000);
}
}
}
示例4: onStopped
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
*
*/
public void onStopped() {
boolean interrupted = false;
while (true) {
try {
if (rwLock.writeLock().tryLock(200, TimeUnit.MILLISECONDS))
break;
else
U.sleep(200);
}
catch (IgniteInterruptedCheckedException | InterruptedException ignore) {
interrupted = true;
}
}
if (interrupted)
Thread.currentThread().interrupt();
try {
state.set(State.STOPPED);
}
finally {
rwLock.writeLock().unlock();
}
}
示例5: main
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* @param args Arguments.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
System.out.println("Starting test server node.");
IgniteConfiguration cfg = CacheConfigurationP2PTest.createConfiguration();
try (Ignite ignite = Ignition.start(cfg)) {
System.out.println(CacheConfigurationP2PTest.NODE_START_MSG);
U.sleep(Long.MAX_VALUE);
}
}
示例6: main
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Starts up two nodes with specified cache configuration on pre-defined endpoints.
*
* @param args Command line arguments, none required.
* @throws IgniteCheckedException In case of any exception.
*/
public static void main(String[] args) throws IgniteCheckedException {
System.setProperty("CLIENTS_MODULE_PATH", U.resolveIgnitePath("modules/clients").getAbsolutePath());
try (Ignite g = G.start("modules/clients/src/test/resources/spring-server-ssl-node.xml")) {
U.sleep(Long.MAX_VALUE);
}
}
示例7: testDeleteFragmentizing
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* @throws Exception If failed.
*/
public void testDeleteFragmentizing() throws Exception {
IgfsImpl igfs = (IgfsImpl)grid(0).fileSystem("igfs");
for (int i = 0; i < 30; i++) {
IgfsPath path = new IgfsPath("/someFile" + i);
try (IgfsOutputStream out = igfs.create(path, true)) {
for (int j = 0; j < 5 * IGFS_GROUP_SIZE; j++)
out.write(new byte[IGFS_BLOCK_SIZE]);
}
U.sleep(200);
}
igfs.clear();
GridTestUtils.retryAssert(log, 50, 100, new CA() {
@Override public void apply() {
for (int i = 0; i < NODE_CNT; i++) {
IgniteEx g = grid(i);
GridCacheAdapter<Object, Object> cache = ((IgniteKernal)g).internalCache(
g.igfsx("igfs").configuration().getDataCacheConfiguration().getName());
assertTrue("Data cache is not empty [keys=" + cache.keySet() +
", node=" + g.localNode().id() + ']', cache.isEmpty());
}
}
});
}
示例8: body
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void body() throws InterruptedException, IgniteInterruptedCheckedException {
try {
boolean reset = false;
while (!closed && !Thread.currentThread().isInterrupted()) {
try {
if (reset)
selector = createSelector(locAddr);
accept();
}
catch (IgniteCheckedException e) {
if (!Thread.currentThread().isInterrupted()) {
U.error(log, "Failed to accept remote connection (will wait for " + ERR_WAIT_TIME + "ms).",
e);
U.sleep(ERR_WAIT_TIME);
reset = true;
}
}
}
}
finally {
closeSelector(); // Safety.
}
}
示例9: reply
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* @param n Node.
* @param d DemandMessage
* @param s Supply message.
* @return {@code True} if message was sent, {@code false} if recipient left grid.
* @throws IgniteCheckedException If failed.
*/
private boolean reply(ClusterNode n,
GridDhtPartitionDemandMessage d,
GridDhtPartitionSupplyMessage s,
T3<UUID, Integer, AffinityTopologyVersion> scId)
throws IgniteCheckedException {
try {
if (log.isDebugEnabled())
log.debug("Replying to partition demand [node=" + n.id() + ", demand=" + d + ", supply=" + s + ']');
grp.shared().io().sendOrderedMessage(n, d.topic(), s, grp.ioPolicy(), d.timeout());
// Throttle preloading.
if (grp.config().getRebalanceThrottle() > 0)
U.sleep(grp.config().getRebalanceThrottle());
return true;
}
catch (ClusterTopologyCheckedException ignore) {
if (log.isDebugEnabled())
log.debug("Failed to send partition supply message because node left grid: " + n.id());
synchronized (scMap) {
clearContext(scMap.remove(scId), log);
}
return false;
}
}
示例10: stopNodeAndSleep
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Stop the very first grid node (the one with 0 index) and sleep for the given amount of time.
*
* @param timeout Sleep timeout in milliseconds.
* @throws Exception If failed.
*/
private void stopNodeAndSleep(long timeout) throws Exception {
stopGrid(getTestIgniteInstanceName(0), false, false);
info("Stopped grid.");
U.sleep(timeout);
}
示例11: afterTest
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
rnd = null;
try {
if (asyncRunFut != null && !asyncRunFut.isDone()) {
stop.set(true);
try {
asyncRunFut.cancel();
asyncRunFut.get(60000);
}
catch (Throwable ex) {
//Ignore
}
}
if (reuseList != null) {
long size = reuseList.recycledPagesCount();
assertTrue("Reuse size: " + size, size < 7000);
}
for (int i = 0; i < 10; i++) {
if (acquiredPages() != 0) {
System.out.println("!!!");
U.sleep(10);
}
}
assertEquals(0, acquiredPages());
}
finally {
pageMem.stop();
MAX_PER_PAGE = 0;
PUT_INC = 1;
RMV_INC = -1;
CNT = 10;
}
}
示例12: stateChangeFailover2
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* @param activate If {@code true} tests activation, otherwise deactivation.
* @throws Exception If failed.
*/
private void stateChangeFailover2(boolean activate) throws Exception {
// Nodes 1 and 4 do not reply to coordinator.
IgniteInternalFuture<?> fut = startNodesAndBlockStatusChange(4, 4, 3, !activate, 1, 4);
client = false;
// Start more nodes while transition is in progress.
IgniteInternalFuture startFut1 = GridTestUtils.runAsync(new Callable() {
@Override public Object call() throws Exception {
startGrid(8);
return null;
}
}, "start-node1");
IgniteInternalFuture startFut2 = GridTestUtils.runAsync(new Callable() {
@Override public Object call() throws Exception {
startGrid(9);
return null;
}
}, "start-node2");
U.sleep(500);
// Stop coordinator.
stopGrid(getTestIgniteInstanceName(0), true, false);
stopGrid(getTestIgniteInstanceName(1), true, false);
stopGrid(getTestIgniteInstanceName(4), true, false);
fut.get();
startFut1.get();
startFut2.get();
client = false;
startGrid(0);
startGrid(1);
client = true;
startGrid(4);
if (!activate) {
checkNoCaches(10);
ignite(0).active(true);
}
checkCaches1(10);
}
示例13: testMixedAddrs
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* @throws Exception If failed.
*/
@SuppressWarnings("ConstantConditions")
public void testMixedAddrs() throws Exception {
restPort = REST_PORT;
startGrids(gridCount());
beforeJob();
stopGrid(1);
U.sleep(5000);
checkJobSubmit(configMixed());
startGrid(1);
awaitPartitionMapExchange();
}
示例14: testRunClient
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Runs client test
*/
@SuppressWarnings("InfiniteLoopStatement")
public void testRunClient() {
Socket sock = new Socket();
OutputStream out = null;
InputStream in = null;
try {
Random r = new Random();
sock.connect(new InetSocketAddress(HOSTNAME, PORT));
out = sock.getOutputStream();
in = new BufferedInputStream(sock.getInputStream());
while (true) {
byte[] msg = createMessage(r.nextInt(1024) + 1);
long start = System.currentTimeMillis();
System.out.println(">>>>>>> [" + start + "] sending message, " + msg.length + " bytes");
writeMessage(out, msg);
byte[] resp = readMessage(in);
if (resp.length != msg.length)
throw new IOException("Invalid response");
long end = System.currentTimeMillis();
System.out.println(">>>>>>> [" + end + "] response received, " + msg.length + " bytes");
System.out.println("======= Response received within " + (end - start) + "ms\r\n");
U.sleep(30);
}
}
catch (Exception e) {
System.out.println("Finishing test thread: " + e.getMessage());
}
finally {
U.closeQuiet(out);
U.closeQuiet(in);
U.closeQuiet(sock);
}
}
示例15: testCreateConsistencyMultithreaded
import org.apache.ignite.internal.util.typedef.internal.U; //导入方法依赖的package包/类
/**
* Ensure create consistency when multiple threads writes to the same file.
*
* @throws Exception If failed.
*/
public void testCreateConsistencyMultithreaded() throws Exception {
final AtomicBoolean stop = new AtomicBoolean();
final AtomicInteger createCtr = new AtomicInteger(); // How many times the file was re-created.
final AtomicReference<Exception> err = new AtomicReference<>();
igfs.create(FILE, false).close();
int threadCnt = 50;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@SuppressWarnings("ThrowFromFinallyBlock")
@Override public void run() {
while (!stop.get() && err.get() == null) {
IgfsOutputStream os = null;
try {
os = igfs.create(FILE, true);
os.write(chunk);
os.close();
createCtr.incrementAndGet();
}
catch (IgniteException ignored) {
// No-op.
}
catch (IOException e) {
err.compareAndSet(null, e);
Throwable[] chain = X.getThrowables(e);
Throwable cause = chain[chain.length - 1];
System.out.println("Failed due to IOException exception. Cause:");
cause.printStackTrace(System.out);
}
finally {
if (os != null)
try {
os.close();
}
catch (IOException ioe) {
throw new IgniteException(ioe);
}
}
}
}
}, threadCnt);
long startTime = U.currentTimeMillis();
while (err.get() == null
&& createCtr.get() < 500
&& U.currentTimeMillis() - startTime < 60 * 1000)
U.sleep(100);
stop.set(true);
fut.get();
awaitFileClose(igfs.asSecondary(), FILE);
if (err.get() != null) {
X.println("Test failed: rethrowing first error: " + err.get());
throw err.get();
}
checkFileContent(igfs, FILE, chunk);
}