Skip to content
This repository
Browse code

BroadcastPartitioner to allow sending events to all nodes.

  • Loading branch information...
commit a206a9c21807d4bcc406abd1ea9dc0b4115f2d47 1 parent e7f376c
authored January 24, 2011
43  src/main/java/io/s4/dispatcher/partitioner/BroadcastPartitioner.java
... ...
@@ -0,0 +1,43 @@
  1
+/*
  2
+ * Copyright (c) 2010 Yahoo! 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
+ * 	        http://www.apache.org/licenses/LICENSE-2.0
  8
+ * 
  9
+ * Unless required by applicable law or agreed to in writing,
  10
+ * software distributed under the License is distributed on an
  11
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12
+ * either express or implied. See the License for the specific
  13
+ * language governing permissions and limitations under the
  14
+ * License. See accompanying LICENSE file. 
  15
+ */
  16
+package io.s4.dispatcher.partitioner;
  17
+
  18
+import java.util.ArrayList;
  19
+import java.util.List;
  20
+
  21
+/**
  22
+ * Partition events to be sent to all parts. This can be used in conjunction
  23
+ * with a Dispatcher to broadcast events.
  24
+ */
  25
+public class BroadcastPartitioner implements Partitioner {
  26
+    @Override
  27
+    public List<CompoundKeyInfo> partition(String streamName, Object event,
  28
+                                           int partitionCount) {
  29
+
  30
+        List<CompoundKeyInfo> partitionInfoList = new ArrayList<CompoundKeyInfo>();
  31
+
  32
+        // assign to all partitions
  33
+        for (int i = 0; i < partitionCount; ++i) {
  34
+            CompoundKeyInfo partitionInfo = new CompoundKeyInfo();
  35
+
  36
+            partitionInfo.setPartitionId(i);
  37
+
  38
+            partitionInfoList.add(partitionInfo);
  39
+        }
  40
+
  41
+        return partitionInfoList;
  42
+    }
  43
+}

0 notes on commit a206a9c

Please sign in to comment.
Something went wrong with that request. Please try again.