@SuppressWarnings({"unchecked"}) private DataType<?> getEventType(EventStream stream, ClassLoader loader) throws ClassNotFoundException { Class<?> type; List<String> eventTypes = stream.getDefinition().getEventTypes(); if (eventTypes.isEmpty()) { // default to Object if there are no event types type = Object.class; } else { type = ParameterTypeHelper.loadClass(eventTypes.get(0), loader); } return new JavaClass(type); }
@SuppressWarnings({"unchecked"}) private DataType<?> getEventTypeForConnection(ChannelConnection connection, ClassLoader loader) throws BrokerException { PhysicalEventStreamDefinition eventStreamDefinition = connection.getEventStream().getDefinition(); if (!eventStreamDefinition.getEventTypes().isEmpty()) { try { String eventType = eventStreamDefinition.getEventTypes().get(0); Class<?> type = ParameterTypeHelper.loadClass(eventType, loader); return new JavaClass(type); } catch (ClassNotFoundException e) { throw new BrokerException(e); } } else { return new JavaClass<Object>(Object.class); } }
/** * Adds event transformers to convert an event from one format to another. * * @param streamDefinition the stream definition * @param stream the stream being created * @param loader the target classloader to use for the transformation * @throws BuilderException if there is an error adding a filter */ @SuppressWarnings({"unchecked"}) private void addTransformer(PhysicalEventStreamDefinition streamDefinition, EventStream stream, ClassLoader loader) throws BuilderException { if (transformerRegistry == null) { // no transformer registry configured (e.g. during bootstrap) so skip return; } List<String> eventTypes = streamDefinition.getEventTypes(); String stringifiedType = eventTypes.get(0); try { DataType<Object> type = new JavaClass(loader.loadClass(stringifiedType)); TransformerHandler handler = new TransformerHandler(type, transformerRegistry); stream.addHandler(handler); } catch (ClassNotFoundException e) { throw new BuilderException(e); } }