PageRenderTime 21ms CodeModel.GetById 8ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/hazelcast/src/main/java/com/hazelcast/impl/NamedExecutorService.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 52 lines | 27 code | 10 blank | 15 comment | 0 complexity | c05467792ce5bcf4efe7f3b10cbc076d MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.impl;
18
19import com.hazelcast.impl.executor.ParallelExecutor;
20
21public class NamedExecutorService {
22
23    private final String name;
24    private final ParallelExecutor parallelExecutor;
25    private final ExecutionLoadBalancer executionLoadBalancer;
26
27    public NamedExecutorService(String name, ParallelExecutor parallelExecutor) {
28        this.name = name;
29        this.parallelExecutor = parallelExecutor;
30        this.executionLoadBalancer = new RoundRobinLoadBalancer();
31    }
32
33    public void appendState(StringBuffer sbState) {
34        sbState.append("\nExecutor." + name + ".size=" + parallelExecutor.getPoolSize());
35    }
36
37    public void stop() {
38        parallelExecutor.shutdown();
39    }
40
41    public void execute(Runnable runnable) {
42        parallelExecutor.execute(runnable);
43    }
44
45    public void executeOrderedRunnable(int hash, Runnable runnable) {
46        parallelExecutor.execute(runnable, hash);
47    }
48
49    public ExecutionLoadBalancer getExecutionLoadBalancer() {
50        return executionLoadBalancer;
51    }
52}