use of com.optimizely.ab.Optimizely in project android-sdk by optimizely.
the class OptimizelyManager method buildOptimizely.
private OptimizelyClient buildOptimizely(@NonNull Context context, @NonNull String datafile) throws ConfigParseException {
EventHandler eventHandler = getEventHandler(context);
EventBatch.ClientEngine clientEngine = OptimizelyClientEngine.getClientEngineFromContext(context);
Optimizely.Builder builder = Optimizely.builder();
builder.withEventHandler(eventHandler);
builder.withEventProcessor(eventProcessor);
if (datafileHandler instanceof DefaultDatafileHandler) {
DefaultDatafileHandler handler = (DefaultDatafileHandler) datafileHandler;
handler.setDatafile(datafile);
builder.withConfigManager(handler);
} else {
builder.withDatafile(datafile);
}
// override client sdk name/version to be included in events
builder.withClientInfo(clientEngine, sdkVersion);
if (errorHandler != null) {
builder.withErrorHandler(errorHandler);
}
builder.withUserProfileService(userProfileService);
builder.withNotificationCenter(notificationCenter);
builder.withDefaultDecideOptions(defaultDecideOptions);
Optimizely optimizely = builder.build();
return new OptimizelyClient(optimizely, LoggerFactory.getLogger(OptimizelyClient.class));
}
use of com.optimizely.ab.Optimizely in project android-sdk by optimizely.
the class OptimizelyClientTest method setup.
@Before
public void setup() {
Field field = null;
try {
field = Optimizely.class.getDeclaredField("notificationCenter");
// Mark the field as public so we can toy with it
field.setAccessible(true);
// Get the Modifiers for the Fields
Field modifiersField = Field.class.getDeclaredField("modifiers");
// Allow us to change the modifiers
modifiersField.setAccessible(true);
// Remove final modifier from field by blanking out the bit that says "FINAL" in the Modifiers
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
// Set new value
field.set(optimizely, notificationCenter);
when(optimizely.isValid()).thenReturn(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
use of com.optimizely.ab.Optimizely in project java-sdk by optimizely.
the class Example method main.
public static void main(String[] args) throws InterruptedException {
Optimizely optimizely = OptimizelyFactory.newDefaultInstance("BX9Y3bTa4YErpHZEMpAwHm");
Example example = new Example(optimizely);
Random random = new Random();
for (int i = 0; i < 10; i++) {
String userId = String.valueOf(random.nextInt(Integer.MAX_VALUE));
example.processVisitor(userId, Collections.emptyMap());
TimeUnit.MILLISECONDS.sleep(500);
}
}
Aggregations