Search in sources :

Example 1 with Optimizely

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));
}
Also used : EventHandler(com.optimizely.ab.event.EventHandler) DefaultEventHandler(com.optimizely.ab.android.event_handler.DefaultEventHandler) Optimizely(com.optimizely.ab.Optimizely) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) DefaultDatafileHandler(com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)

Example 2 with Optimizely

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();
    }
}
Also used : Field(java.lang.reflect.Field) Optimizely(com.optimizely.ab.Optimizely) Before(org.junit.Before)

Example 3 with Optimizely

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);
    }
}
Also used : Random(java.util.Random) Optimizely(com.optimizely.ab.Optimizely)

Aggregations

Optimizely (com.optimizely.ab.Optimizely)3 DefaultDatafileHandler (com.optimizely.ab.android.datafile_handler.DefaultDatafileHandler)1 DefaultEventHandler (com.optimizely.ab.android.event_handler.DefaultEventHandler)1 EventHandler (com.optimizely.ab.event.EventHandler)1 EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)1 Field (java.lang.reflect.Field)1 Random (java.util.Random)1 Before (org.junit.Before)1