Search in sources :

Example 1 with EventSerializers

use of org.apache.phoenix.flume.serializer.EventSerializers in project phoenix by apache.

the class PhoenixConsumer method initializeSerializer.

/**
     * Initializes the serializer for kafka messages.
     * @param context
     * @param eventSerializerType
     */
private void initializeSerializer(final Context context, final String eventSerializerType) {
    String serializerClazz = null;
    EventSerializers eventSerializer = null;
    try {
        eventSerializer = EventSerializers.valueOf(eventSerializerType.toUpperCase());
    } catch (IllegalArgumentException iae) {
        serializerClazz = eventSerializerType;
    }
    final Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(FlumeConstants.CONFIG_SERIALIZER_PREFIX));
    copyPropertiesToSerializerContext(context, serializerContext);
    try {
        @SuppressWarnings("unchecked") Class<? extends EventSerializer> clazz = null;
        if (serializerClazz == null) {
            clazz = (Class<? extends EventSerializer>) Class.forName(eventSerializer.getClassName());
        } else {
            clazz = (Class<? extends EventSerializer>) Class.forName(serializerClazz);
        }
        serializer = clazz.newInstance();
        serializer.configure(serializerContext);
    } catch (Exception e) {
        logger.error("Could not instantiate event serializer.", e);
        Throwables.propagate(e);
    }
}
Also used : Context(org.apache.flume.Context) EventSerializers(org.apache.phoenix.flume.serializer.EventSerializers) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with EventSerializers

use of org.apache.phoenix.flume.serializer.EventSerializers in project phoenix by apache.

the class PhoenixSink method initializeSerializer.

/**
     * Initializes the serializer for flume events.
     * @param eventSerializerType
     */
private void initializeSerializer(final Context context, final String eventSerializerType) {
    String serializerClazz = null;
    EventSerializers eventSerializer = null;
    try {
        eventSerializer = EventSerializers.valueOf(eventSerializerType.toUpperCase());
    } catch (IllegalArgumentException iae) {
        serializerClazz = eventSerializerType;
    }
    final Context serializerContext = new Context();
    serializerContext.putAll(context.getSubProperties(FlumeConstants.CONFIG_SERIALIZER_PREFIX));
    copyPropertiesToSerializerContext(context, serializerContext);
    try {
        @SuppressWarnings("unchecked") Class<? extends EventSerializer> clazz = null;
        if (serializerClazz == null) {
            clazz = (Class<? extends EventSerializer>) Class.forName(eventSerializer.getClassName());
        } else {
            clazz = (Class<? extends EventSerializer>) Class.forName(serializerClazz);
        }
        serializer = clazz.newInstance();
        serializer.configure(serializerContext);
    } catch (Exception e) {
        logger.error("Could not instantiate event serializer.", e);
        Throwables.propagate(e);
    }
}
Also used : Context(org.apache.flume.Context) EventSerializers(org.apache.phoenix.flume.serializer.EventSerializers) SQLException(java.sql.SQLException) EventDeliveryException(org.apache.flume.EventDeliveryException) ChannelException(org.apache.flume.ChannelException)

Aggregations

SQLException (java.sql.SQLException)2 Context (org.apache.flume.Context)2 EventSerializers (org.apache.phoenix.flume.serializer.EventSerializers)2 IOException (java.io.IOException)1 ChannelException (org.apache.flume.ChannelException)1 EventDeliveryException (org.apache.flume.EventDeliveryException)1