当前位置: 首页>>代码示例>>Java>>正文


Java IExecutorService类代码示例

本文整理汇总了Java中com.hazelcast.core.IExecutorService的典型用法代码示例。如果您正苦于以下问题:Java IExecutorService类的具体用法?Java IExecutorService怎么用?Java IExecutorService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IExecutorService类属于com.hazelcast.core包,在下文中一共展示了IExecutorService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
public static void main(String[] args) {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    IExecutorService executor = hz.getExecutorService("executor");
    ExecutionCallback<Long> executionCallback = new ExecutionCallback<Long>() {
        public void onFailure(Throwable t) {
            t.printStackTrace();
        }

        public void onResponse(Long response) {
            System.out.println("Result: " + response);
        }
    };
    executor.submit(new FibonacciCallable(10), executionCallback);
    System.out.println("Fibonacci task submitted");
}
 
开发者ID:gAmUssA,项目名称:jpoint-2016-computing-talk,代码行数:16,代码来源:MasterMember.java

示例2: multiTask

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
/**
 * Submits a task to multiple members of the Hazelcast task cluster.
 * 
 * @param task
 *        The task
 * @param where
 *        A {@link MemberSelector}, an {@link Iterable} of {@link Member}, a
 *        string (comma-separated member tags), or null for all members
 * @return A map of members to futures for the task
 */
@SuppressWarnings("unchecked")
private <T> Map<Member, Future<T>> multiTask( SerializableApplicationTask<T> task, Object where )
{
	IExecutorService executor = getHazelcastExecutorService();

	if( where instanceof String )
		return executor.submitToMembers( task, new TaggedMembers( HAZELCAST_MEMBER_TAGS_ATTRIBUTE, (String) where ) );
	else if( where instanceof MemberSelector )
		return executor.submitToMembers( task, (MemberSelector) where );
	else if( where instanceof Collection )
		return executor.submitToMembers( task, (Collection<Member>) where );
	else if( where instanceof Iterable )
	{
		ArrayList<Member> members = new ArrayList<Member>();
		for( Member member : (Iterable<Member>) where )
			members.add( member );
		return executor.submitToMembers( task, members );
	}
	else
		return executor.submitToAllMembers( task );
}
 
开发者ID:tliron,项目名称:prudence,代码行数:32,代码来源:DistributedApplicationService.java

示例3: notifyAdmins

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
private static void notifyAdmins(HazelcastInstance sysInstance, Member local, String schemaName, boolean initialized) {

    	int cnt = 0;
		IExecutorService execService = sysInstance.getExecutorService(PN_XDM_SYSTEM_POOL);
        Set<Member> admins = getAdmins(sysInstance);

		// notify admin about new schema node (local)
		// hzInstance -> system instance, SchemaManagement is in its context
		// submit task to init member in admin..
		SchemaAdministrator adminTask = new SchemaAdministrator(schemaName, !initialized, local.getUuid());
       	Map<Member, Future<Boolean>> result = execService.submitToMembers(adminTask, admins);
        
        for (Map.Entry<Member, Future<Boolean>> e: result.entrySet()) {
   	       	try {
   				if (e.getValue().get()) {
   					cnt++;
   				} else {
   					logger.info("notifyAdmins; failed admin notification on member {}", e.getKey()); 
   				}
   			} catch (InterruptedException | ExecutionException ex) {
   				logger.error("notifyAdmins.error; ", ex);
   	        }
    	}
		logger.debug("notifyAdmins; notified {} admin nodes out of {} admins", cnt, admins.size());
    }
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:26,代码来源:BagriCacheServer.java

示例4: submit

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
static <T> ServiceCommandResult<T> submit(HazelcastInstance instance, ServiceCommand<T> command, ClusterMember member) {
  IExecutorService exService = instance.getExecutorService(HAZELCAST_EXECUTOR_NAME) ;
  HazelcastMemberSelector selector = new HazelcastMemberSelector(instance) ;
  Member hzmember = selector.selectMember(member) ;
  ServiceCommandWrapper<T> wrapper = new ServiceCommandWrapper<T>(command) ;
  Future<T> future = exService.submitToMember(wrapper, hzmember) ;
  ServiceCommandResult<T> result = new ServiceCommandResult<T>() ;
  result.setFromMember(member);
  try {
    T ret = future.get(command.getTimeout(), TimeUnit.MILLISECONDS) ;
    result.setResult(ret);
    return result ;
  } catch (InterruptedException | ExecutionException | TimeoutException error) {
    result.setError(error) ;
    return result ;
  }
}
 
开发者ID:DemandCube,项目名称:NeverwinterDP-Commons,代码行数:18,代码来源:Util.java

示例5: main

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    HazelcastInstance hz = Hazelcast.newHazelcastInstance();
    Map<String, Integer> map = hz.getMap("map");
    for (int k = 0; k < 42; k++)
        map.put(UUID.randomUUID().toString(), 1);

    IExecutorService executor = hz.getExecutorService("executor");
    Map<Member, Future<Integer>> result = executor.submitToAllMembers(new SumTask());

    int sum = 0;
    for (Future<Integer> future : result.values())
        sum += future.get();

    System.out.println("Result: " + sum);
}
 
开发者ID:gAmUssA,项目名称:jpoint-2016-computing-talk,代码行数:16,代码来源:MasterMember.java

示例6: getIExecutorService

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Override
public IExecutorService getIExecutorService(String name)
{
    name = Objects.requireNonNull(name);

    final IExecutorService valu = getBeanSafely(name, IExecutorService.class);

    if (null != valu)
    {
        return valu;
    }
    return hz().getExecutorService(name);
}
 
开发者ID:ahome-it,项目名称:ahome-tooling-server-hazelcast,代码行数:14,代码来源:HazelcastContextInstance.java

示例7: initSchema

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
private static boolean initSchema(HazelcastInstance hzInstance, Member member, Schema schema) {
   	
	logger.trace("initSchema.enter; schema: {}", schema);
	SchemaInitiator init = new SchemaInitiator(schema);
	IExecutorService execService = hzInstance.getExecutorService(PN_XDM_SYSTEM_POOL);
      	Future<Boolean> result = execService.submitToMember(init, member);
      	Boolean ok = false;
      	try {
		ok = result.get();
	} catch (InterruptedException | ExecutionException ex) {
		logger.error("initSchema.error; ", ex);
       }
	logger.info("initSchema.exit; schema {} {}initialized", schema.getName(), ok ? "" : "NOT ");
	return ok;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:16,代码来源:BagriCacheServer.java

示例8: updateNodesInCluster

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
protected int updateNodesInCluster(Node node, String comment) {
	
	logger.trace("updateNodesInCluster.enter; node: {}", node);
	
	// do this on Named nodes only, not on ALL nodes!
	Set<Member> all = hzInstance.getCluster().getMembers();
	List<Member> named = new ArrayList<Member>(all.size());
	String name = node.getName();
	for (Member member: all) {
		if (name.equals(member.getStringAttribute(pn_cluster_node_name))) {
			named.add(member);
		}
	}

	int cnt = 0;
	if (named.size() > 0) {
		logger.info("updateNodesInCluster; going to update {} Members", named.size());
		
		NodeOptionSetter setter = new NodeOptionSetter(getAdmin(), comment, node.getOptions());
		IExecutorService execService = hzInstance.getExecutorService(PN_XDM_SYSTEM_POOL);
		
		Map<Member, Future<Boolean>> result = execService.submitToMembers(setter, named);
		for (Map.Entry<Member, Future<Boolean>> entry: result.entrySet()) {
			try {
				Boolean ok = entry.getValue().get();
				if (ok) cnt++;
				logger.debug("updateNodesInCluster; Member {} {}updated", entry.getKey(), ok ? "" : "NOT ");
			} catch (InterruptedException | ExecutionException ex) {
				logger.error("updateNodesInCluster.error; ", ex);
			}
		}
	}
	logger.info("updateNodesInCluster.exit; {} Members updated", cnt);
	return cnt;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:36,代码来源:NodeProcessor.java

示例9: call

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Override
public Boolean call() throws Exception {
   	logger.trace("call.enter; schema: {}; init: {}", schemaName, init);
   	//logger.trace("call.enter; HZ: {}; SM: {}", hzInstance, schemaService);
	boolean result = false;
	for (Member member: hzInstance.getCluster().getMembers()) {
		if (uuid.equals(member.getUuid())) {
	    	if (init) {
	    		Schema schema = schemaService.getSchema(schemaName);
	    		SchemaInitiator initTask = new SchemaInitiator(schema);
	    		IExecutorService execService = hzInstance.getExecutorService(PN_XDM_SYSTEM_POOL);
	    		Future<Boolean> initiated = execService.submitToMember(initTask, member);
	    		Boolean ok = false;
	    		try {
	    			ok = initiated.get();
	    		} catch (InterruptedException | ExecutionException ex) {
	    			logger.error("initSchema.error; ", ex);
	    		}
	    	}
			schemaService.initMember(member);
			result = true;
			break;
		}
	}
   	logger.trace("call.exit; returning: {} for member: {}", result, uuid);
	return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:28,代码来源:SchemaAdministrator.java

示例10: testTask

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Test
public void testTask() throws Exception {
  // Submit the hello task on instance 1
  IExecutorService exService = instance1.getExecutorService("default");
  instance2.getCluster().getLocalMember().setStringAttribute("instance", "instance2");
  Map<Member, Future<Object>> futures = exService.submitToAllMembers(new HelloTask());
  Iterator<Future<Object>> itr = futures.values().iterator() ;
  while(itr.hasNext()) {
    Object result = itr.next().get(25, TimeUnit.SECONDS);
    System.out.println(result);
  }
}
 
开发者ID:DemandCube,项目名称:NeverwinterDP-Commons,代码行数:13,代码来源:HazelcastUnitTest.java

示例11: updateIndex

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
public IndexSettingsResponse updateIndex(String indexName, org.lumongo.cluster.message.LumongoIndex.IndexSettings request)
		throws InvalidIndexConfig, MongoException, IOException {
	globalLock.readLock().lock();
	try {
		log.info("Updating index settings for <" + indexName + ">:\n" + JsonFormat.printer().print(request));
		LumongoIndex i = indexMap.get(indexName);
		if (i == null) {
			throw new IndexDoesNotExist(indexName);
		}

		i.updateIndexSettings(request);

		Set<Member> currentMembers = hazelcastManager.getMembers();
		IExecutorService executorService = hazelcastManager.getExecutorService();

		Member self = hazelcastManager.getSelf();

		for (Member m : currentMembers) {
			try {
				ReloadIndexSettingsTask rist = new ReloadIndexSettingsTask(m.getSocketAddress().getPort(), indexName);
				if (!self.equals(m)) {
					Future<Void> dt = executorService.submitToMember(rist, m);
					dt.get();
				}
				else {
					rist.call();
				}
			}
			catch (Exception e) {
				log.error(e.getClass().getSimpleName() + ": ", e);
			}

		}

		return IndexSettingsResponse.newBuilder().build();
	}
	finally {
		globalLock.readLock().unlock();
	}
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:41,代码来源:LumongoIndexManager.java

示例12: setup

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Setup
public void setup() {
    executors = new IExecutorService[executorCount];
    for (int i = 0; i < executors.length; i++) {
        executors[i] = targetInstance.getExecutorService(name + '-' + i);
    }

    executedCounter = targetInstance.getAtomicLong(name + ":ExecutedCounter");
    expectedExecutedCounter = targetInstance.getAtomicLong(name + ":ExpectedExecutedCounter");
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:11,代码来源:ExecutorTest.java

示例13: teardown

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Teardown(global = true)
public void teardown() throws Exception {
    executedCounter.destroy();
    expectedExecutedCounter.destroy();
    for (IExecutorService executor : executors) {
        executor.shutdownNow();
        if (!executor.awaitTermination(120, TimeUnit.SECONDS)) {
            logger.fatal("Time out while waiting for shutdown of executor: " + executor.getName());
        }
        executor.destroy();
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:13,代码来源:ExecutorTest.java

示例14: getExecutorService

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
@Override
public IExecutorService getExecutorService(String s) {
    return null;
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:5,代码来源:WebConfigurerIntTest.java

示例15: HazelcastCommandExecutor

import com.hazelcast.core.IExecutorService; //导入依赖的package包/类
private HazelcastCommandExecutor(IExecutorService executorService) {
    this.executorService = executorService;
}
 
开发者ID:opencredo,项目名称:concursus,代码行数:4,代码来源:HazelcastCommandExecutor.java


注:本文中的com.hazelcast.core.IExecutorService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。