AbstractLocalAsyncWorker implementations represent workers,
+ * which receive local asynchronous message.
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public abstract class AbstractLocalAsyncWorker extends AbstractWorkerAbstractLocalAsyncWorker with the worker role and context.
+ *
+ * @param role The responsibility of worker in cluster, more than one workers can have same responsibility which use
+ * to provide load balancing ability.
+ * @param clusterContext See {@link ClusterWorkerContext}
+ */
+ public AbstractLocalAsyncWorker(Role role, ClusterWorkerContext clusterContext) {
+ super(role, clusterContext);
+ }
+
+ /**
+ * The asynchronous worker always use to persistence data into db, this is the end of the streaming,
+ * so usually no need to create the next worker instance at the time of this worker instance create.
+ *
+ * @throws ProviderNotFoundException When worker provider not found, it will be throw this exception.
+ */
+ @Override
+ public void preStart() throws ProviderNotFoundException {
+ }
+
+ @Override protected final LocalAsyncWorkerRef getSelf() {
+ return workerRef;
+ }
+
+ @Override protected final void putSelfRef(LocalAsyncWorkerRef workerRef) {
+ this.workerRef = workerRef;
+ }
+
+ /**
+ * Receive message
+ *
+ * @param message The persistence data or metric data.
+ * @throws WorkerException The Exception happen in {@link #onWork(Object)}
+ */
+ final public void allocateJob(Object message) throws WorkerException {
+ onWork(message);
+ }
+}
diff --git a/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractLocalAsyncWorkerProvider.java b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractLocalAsyncWorkerProvider.java
new file mode 100644
index 000000000..995408ffc
--- /dev/null
+++ b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractLocalAsyncWorkerProvider.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.stream;
+
+import org.skywalking.apm.collector.core.framework.CollectorContextHelper;
+import org.skywalking.apm.collector.core.queue.QueueCreator;
+import org.skywalking.apm.collector.core.queue.QueueEventHandler;
+import org.skywalking.apm.collector.core.queue.QueueExecutor;
+import org.skywalking.apm.collector.queue.QueueModuleContext;
+import org.skywalking.apm.collector.queue.QueueModuleGroupDefine;
+import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorker;
+import org.skywalking.apm.collector.stream.worker.impl.PersistenceWorkerContainer;
+
+/**
+ * @author peng-yongsheng
+ */
+public abstract class AbstractLocalAsyncWorkerProviderAbstractRemoteWorker implementations represent workers,
+ * which receive remote messages.
+ *
+ * Usually, the implementations are doing persistent, or aggregate works.
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public abstract class AbstractRemoteWorker extends AbstractWorker
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public abstract class AbstractRemoteWorkerProvider
+ * Actually, the AbstractRemoteWorker with the worker role and context.
+ *
+ * @param role If multi-workers are for load balance, they should be more likely called worker instance. Meaning,
+ * each worker have multi instances.
+ * @param clusterContext See {@link ClusterWorkerContext}
+ */
+ protected AbstractRemoteWorker(Role role, ClusterWorkerContext clusterContext) {
+ super(role, clusterContext);
+ }
+
+ /**
+ * This method use for message producer to call for send message.
+ *
+ * @param message The persistence data or metric data.
+ * @throws Exception The Exception happen in {@link #onWork(Object)}
+ */
+ final public void allocateJob(Object message) throws WorkerInvokeException {
+ try {
+ onWork(message);
+ } catch (WorkerException e) {
+ throw new WorkerInvokeException(e.getMessage(), e.getCause());
+ }
+ }
+
+ @Override protected final RemoteWorkerRef getSelf() {
+ return workerRef;
+ }
+
+ @Override protected final void putSelfRef(RemoteWorkerRef workerRef) {
+ this.workerRef = workerRef;
+ }
+}
diff --git a/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractRemoteWorkerProvider.java b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractRemoteWorkerProvider.java
new file mode 100644
index 000000000..90e139a07
--- /dev/null
+++ b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractRemoteWorkerProvider.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.stream;
+
+import org.skywalking.apm.collector.client.grpc.GRPCClient;
+
+/**
+ * The AbstractRemoteWorkerProvider implementations represent providers,
+ * which create instance of cluster workers whose implemented {@link AbstractRemoteWorker}.
+ * implements Executor {
+
+ private final Logger logger = LoggerFactory.getLogger(AbstractWorker.class);
+
+ private final Role role;
+
+ private final ClusterWorkerContext clusterContext;
+
+ public AbstractWorker(Role role, ClusterWorkerContext clusterContext) {
+ this.role = role;
+ this.clusterContext = clusterContext;
+ }
+
+ @Override public final void execute(Object message) {
+ try {
+ onWork(message);
+ } catch (WorkerException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * The data process logic in this method.
+ *
+ * @param message Cast the message object to a expect subclass.
+ * @throws WorkerException Don't handle the exception, throw it.
+ */
+ protected abstract void onWork(Object message) throws WorkerException;
+
+ public abstract void preStart() throws ProviderNotFoundException;
+
+ final public ClusterWorkerContext getClusterContext() {
+ return clusterContext;
+ }
+
+ final public Role getRole() {
+ return role;
+ }
+
+ protected abstract S getSelf();
+
+ protected abstract void putSelfRef(S workerRef);
+}
diff --git a/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractWorkerProvider.java b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractWorkerProvider.java
new file mode 100644
index 000000000..8ade3430a
--- /dev/null
+++ b/apm-collector/apm-collector-component/stream-component/src/main/java/org/skywalking/apm/collector/stream/AbstractWorkerProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017, OpenSkywalking Organization All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Project repository: https://github.com/OpenSkywalking/skywalking
+ */
+
+package org.skywalking.apm.collector.stream;
+
+/**
+ * @author peng-yongsheng
+ */
+public abstract class AbstractWorkerProvider> {
+
+ private final Logger logger = LoggerFactory.getLogger(LocalAsyncWorkerProviderDefineLoader.class);
+
+ @Override public List
> {
+
+ private final Logger logger = LoggerFactory.getLogger(RemoteWorkerProviderDefineLoader.class);
+
+ @Override public List
HashCodeSelector is a simple implementation of {@link WorkerSelector}. It choose {@link WorkerRef}
+ * by message {@link AbstractHashMessage} key's hashcode, so it can use to send the same hashcode message to same {@link
+ * WorkerRef}. Usually, use to database operate which avoid dirty data.
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public class HashCodeSelector implements WorkerSelectorRollingSelector is a simple implementation of {@link WorkerSelector}.
+ * It choose {@link WorkerRef} nearly random, by round-robin.
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public class RollingSelector implements WorkerSelectorWorkerSelector should be implemented by any class whose instances
+ * are intended to provide select a {@link WorkerRef} from a {@link WorkerRef} list.
+ * WorkerRef is designed to provide a routing ability in the collector cluster
+ *
+ * @author peng-yongsheng
+ * @since v3.0-2017
+ */
+public interface WorkerSelector