@@ -128,49 +128,6 @@ private DecisionResponse<Variation> bucketToVariation(@Nonnull ExperimentCore ex
128128 return new DecisionResponse (null , reasons );
129129 }
130130
131- /**
132- * Determines CMAB traffic allocation for a user based on hashed value from murmurhash3.
133- * This method handles bucketing users into CMAB (Contextual Multi-Armed Bandit) experiments.
134- */
135- @ Nonnull
136- private DecisionResponse <String > bucketToEntityForCmab (@ Nonnull Experiment experiment ,
137- @ Nonnull String bucketingId ) {
138- DecisionReasons reasons = DefaultDecisionReasons .newInstance ();
139-
140- // "salt" the bucket id using the experiment id
141- String experimentId = experiment .getId ();
142- String experimentKey = experiment .getKey ();
143- String combinedBucketId = bucketingId + experimentId ;
144-
145- // Handle CMAB traffic allocation
146- TrafficAllocation cmabTrafficAllocation = new TrafficAllocation ("$" , experiment .getCmab ().getTrafficAllocation ());
147- List <TrafficAllocation > trafficAllocations = java .util .Collections .singletonList (cmabTrafficAllocation );
148-
149- String cmabMessage = reasons .addInfo ("Using CMAB traffic allocation for experiment \" %s\" ." , experimentKey );
150- logger .debug (cmabMessage );
151-
152- int hashCode = MurmurHash3 .murmurhash3_x86_32 (combinedBucketId , 0 , combinedBucketId .length (), MURMUR_HASH_SEED );
153- int bucketValue = generateBucketValue (hashCode );
154- logger .debug ("Assigned bucket {} to user with bucketingId \" {}\" when bucketing to a variation." , bucketValue , bucketingId );
155-
156- String bucketedEntityId = bucketToEntity (bucketValue , trafficAllocations );
157- if (bucketedEntityId != null ) {
158- if ("$" .equals (bucketedEntityId )) {
159- String message = reasons .addInfo ("User with bucketingId \" %s\" is bucketed into CMAB for experiment \" %s\" ." , bucketingId , experimentKey );
160- logger .info (message );
161- } else {
162- // This shouldn't happen in CMAB since we only have "$" entity, but handle gracefully
163- String message = reasons .addInfo ("User with bucketingId \" %s\" is bucketed into entity \" %s\" for experiment \" %s\" ." , bucketingId , bucketedEntityId , experimentKey );
164- logger .info (message );
165- }
166- } else {
167- String message = reasons .addInfo ("User with bucketingId \" %s\" is not bucketed into CMAB for experiment \" %s\" ." , bucketingId , experimentKey );
168- logger .info (message );
169- }
170-
171- return new DecisionResponse <>(bucketedEntityId , reasons );
172- }
173-
174131 /**
175132 * Assign a {@link Variation} of an {@link Experiment} to a user based on hashed value from murmurhash3.
176133 *
@@ -183,24 +140,6 @@ private DecisionResponse<String> bucketToEntityForCmab(@Nonnull Experiment exper
183140 public DecisionResponse <Variation > bucket (@ Nonnull ExperimentCore experiment ,
184141 @ Nonnull String bucketingId ,
185142 @ Nonnull ProjectConfig projectConfig ) {
186-
187- return bucket (experiment , bucketingId , projectConfig , false );
188- }
189-
190- /**
191- * Assign a {@link Variation} of an {@link Experiment} to a user based on hashed value from murmurhash3.
192- *
193- * @param experiment The Experiment in which the user is to be bucketed.
194- * @param bucketingId string A customer-assigned value used to create the key for the murmur hash.
195- * @param projectConfig The current projectConfig
196- * @param useCmab boolean flag to decide whether to handle cmab experiments.
197- * @return A {@link DecisionResponse} including the {@link Variation} that user is bucketed into (or null) and the decision reasons
198- */
199- @ Nonnull
200- public DecisionResponse <Variation > bucket (@ Nonnull ExperimentCore experiment ,
201- @ Nonnull String bucketingId ,
202- @ Nonnull ProjectConfig projectConfig ,
203- @ Nonnull boolean useCmab ) {
204143 DecisionReasons reasons = DefaultDecisionReasons .newInstance ();
205144
206145 // ---------- Bucket User ----------
@@ -233,26 +172,9 @@ public DecisionResponse<Variation> bucket(@Nonnull ExperimentCore experiment,
233172 }
234173 }
235174
236- if (useCmab ){
237- if (experiment instanceof Experiment ) {
238- DecisionResponse <String > decisionResponse = bucketToEntityForCmab ((Experiment ) experiment , bucketingId );
239- reasons .merge (decisionResponse .getReasons ());
240- String entityId = decisionResponse .getResult ();
241- if (entityId ==null ){
242- return new DecisionResponse <>(null , reasons );
243- }
244- Variation variation = new Variation (entityId , entityId ); //return dummy variation for cmab
245- return new DecisionResponse <>(variation , reasons );
246- } else {
247- String message = reasons .addInfo ("ExperimentCore instance is not of type Experiment, cannot perform CMAB bucketing." );
248- logger .info (message );
249- return new DecisionResponse <>(null , reasons );
250- }
251- } else {
252- DecisionResponse <Variation > decisionResponse = bucketToVariation (experiment , bucketingId );
253- reasons .merge (decisionResponse .getReasons ());
254- return new DecisionResponse <>(decisionResponse .getResult (), reasons );
255- }
175+ DecisionResponse <Variation > decisionResponse = bucketToVariation (experiment , bucketingId );
176+ reasons .merge (decisionResponse .getReasons ());
177+ return new DecisionResponse <>(decisionResponse .getResult (), reasons );
256178 }
257179
258180 //======== Helper methods ========//
@@ -270,4 +192,4 @@ int generateBucketValue(int hashCode) {
270192 return (int ) Math .floor (MAX_TRAFFIC_VALUE * ratio );
271193 }
272194
273- }
195+ }
0 commit comments