Example usage for java.util.concurrent Callable Callable

List of usage examples for java.util.concurrent Callable Callable

Introduction

In this page you can find the example usage for java.util.concurrent Callable Callable.

Prototype

Callable

Source Link

Usage

From source file:com.fengduo.bee.service.impl.message.SmsServiceImpl.java

/**
 * ????/*from   w w w. ja v  a 2  s .  c o  m*/
 * 
 * @param mobiles
 * @return
 */
@Override
public boolean sendCheckCode(final String phone) {
    executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            final String code = Identities.randomNum(6);
            Map<String, String> map = new HashMap<String, String>();
            map.put("checkCode", code);
            boolean flag = sendSelfDefiningMsg(phone, map, SmsProjectEnum.CHECKCODE.getValue());

            if (flag) {
                // 
                JedisUtils.set(phone, code, SMSCODE_EXPIRE);
            }
            return flag;
        }

    });
    return true;
}

From source file:net.javacrumbs.futureconverter.common.test.spring.SpringOriginalFutureTestHelper.java

@Override
public ListenableFuture<String> createRunningFuture() {
    return executor.submitListenable(new Callable<String>() {
        @Override/*w w w .j ava2  s.c om*/
        public String call() throws Exception {
            waitForSignal();
            return AbstractConverterTest.VALUE;
        }
    });
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.MultimediaDaoImplTest.java

@Test
public void testCreateMultimedia() {
    this.execute(new Callable<Object>() {
        @Override/*from  w  w  w .j  a  va  2s  .  c o m*/
        public Object call() {
            final BlackboardMultimediaResponse response = new BlackboardMultimediaResponse();
            response.setCreatorId("test@example.com");
            response.setDescription("super sweet media");
            response.setMultimediaId(183838);
            response.setSize(1024);

            final Multimedia mm = dao.createMultimedia(response, "aliens_exist.pdf");
            assertNotNull(mm);

            assertEquals(1024, mm.getSize());
            assertEquals(183838, mm.getBbMultimediaId());

            Multimedia pullFromDB = dao.getMultimediaByBlackboardId(mm.getBbMultimediaId());
            assertNotNull(pullFromDB);

            return null;
        }
    });
}

From source file:com.link_intersystems.lang.reflect.SerializableMethodTest.java

@Test
public void securityException() throws Throwable {
    Method method = SerializableMethodTest.class.getDeclaredMethod("someTestMethod", int.class, int[].class,
            String.class);
    final SecurityExceptionSerializableMethod serializableMethod = new SecurityExceptionSerializableMethod(
            method);/*w ww  . java 2s.co m*/

    Assertion.assertCause(SecurityException.class, new Callable<Object>() {

        public Object call() throws Exception {
            SerializableMethod cloneSerializable = cloneSerializable(serializableMethod);
            return cloneSerializable;
        }
    });
}

From source file:bad.robot.http.apache.ApacheExceptionWrappingExecutorTest.java

private static Callable<Object> throwsException(final Exception e) {
    return new Callable<Object>() {
        @Override/* w ww  .ja  va2  s . c o m*/
        public Object call() throws Exception {
            throw e;
        }
    };
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.PresentationDaoImplTest.java

@Test
public void testCreatePresentation() {
    this.execute(new Callable<Object>() {
        @Override//w ww  .  j  a  v  a 2 s  .  c  o  m
        public Object call() {
            final BlackboardPresentationResponse response = new BlackboardPresentationResponse();
            response.setCreatorId("test@example.com");
            response.setDescription("super sweet media");
            response.setPresentationId(183838);
            response.setSize(1024);

            final Presentation pres = dao.createPresentation(response, "aliens_exist.pdf");
            assertNotNull(pres);

            assertEquals(1024, pres.getSize());
            assertEquals(183838, pres.getBbPresentationId());

            Presentation pullFromDB = dao.getPresentationByBlackboardId(pres.getBbPresentationId());
            assertNotNull(pullFromDB);

            return null;
        }
    });
}

From source file:com.basho.riak.client.raw.pbc.PBMapReduceResult.java

/**
 * @param response//from www .ja v  a2  s.  c  om
 */
private PBMapReduceResult(final MapReduceResponseSource response) {
    this.objectMapper = new ObjectMapper();

    // Getting the actual result from PB stream must be run once only
    rawResultTask = new FutureTask<String>(new Callable<String>() {

        public String call() throws Exception {
            JSONArray results = MapReduceResponseSource.readAllResults(response);
            return results.toString();
        }
    });
}

From source file:org.fishwife.jrugged.spring.retry.ExtendedRetryTemplate.java

/***
 * Construct a {@link Callable} which wraps the given {@link Callable},
 * and who's {@link java.util.concurrent.Callable#call()} method will execute
 * the callable via this {@link ExtendedRetryTemplate}
 *
 * @param callable The callable to wrap// w  w w . ja  v a 2  s.  co  m
 * @param <T> The return type of the callback
 * @return
 */
public <T> Callable<T> asCallable(final Callable<T> callable) {
    return new Callable<T>() {
        public T call() throws Exception {
            return ExtendedRetryTemplate.this.execute(new RetryCallback<T>() {
                public T doWithRetry(RetryContext retryContext) throws Exception {
                    return callable.call();
                }
            });
        }
    };
}

From source file:net.pms.io.NullProcessWrapperConsumer.java

@Override
@Nullable/*w  w w .j  av a2  s .  c o  m*/
public FutureTask<Void> consume(@Nullable final InputStream inputStream, @Nullable String threadName) {
    if (inputStream == null) {
        return null;
    }
    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws IOException {
            List<String> result = LOGGER.isTraceEnabled() ? new ArrayList<String>() : null;
            Charset outputCharset;
            if (Services.WINDOWS_CONSOLE != null) {
                outputCharset = Services.WINDOWS_CONSOLE;
            } else {
                outputCharset = StandardCharsets.UTF_8;
            }

            try (BufferedReader reader = new BufferedReader(
                    new InputStreamReader(inputStream, outputCharset))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    if (result != null) {
                        result.add(line);
                    }
                }
            }
            if (result != null) {
                LOGGER.trace("Discarded {} lines of process output:", result.size());
                for (String line : result) {
                    LOGGER.trace("  Process output: {}", line);
                }
            }
            return null;
        }
    };
    FutureTask<Void> result = new FutureTask<Void>(callable);
    Thread runner;
    if (isBlank(threadName)) {
        runner = new Thread(result);
    } else {
        runner = new Thread(result, threadName);
    }
    runner.start();
    return result;
}

From source file:com.link_intersystems.lang.reflect.SerializableConstructorTest.java

@Test
public void securityException() throws Throwable {
    Constructor<ConstructorSerializationTestClass> constructor = ConstructorSerializationTestClass.class
            .getDeclaredConstructor(String.class);
    final SerializableConstructor serializableConstructor = new SecurityExceptionSerializableConstructor(
            constructor);//from   w  w  w.  java2 s  .  c  o  m
    Assertion.assertCause(SecurityException.class, new Callable<Object>() {

        public Object call() throws Exception {
            return SerializationUtils.clone(serializableConstructor);
        }
    });
}