Package io.s4.dispatcher.partitioner

Examples of io.s4.dispatcher.partitioner.KeyInfo


            EventClock s4EventClock = (EventClock)s4Clock;
            s4EventClock.updateTime(seedTime);
            System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime());
        }
       
        PEContainer peContainer = (PEContainer) context.getBean("peContainer");

        Watcher w = (Watcher) context.getBean("watcher");
        w.setConfigFilename(configPath);

       
        // load extension modules
        String[] configFileNames = getModuleConfigFiles(extsHome, prop);
        if (configFileNames.length > 0) {
            String[] configFileUrls = new String[configFileNames.length];
            for (int i = 0; i < configFileNames.length; i++) {
                configFileUrls[i] = "file:" + configFileNames[i];
            }
            context = new FileSystemXmlApplicationContext(configFileUrls,
                                                          context);
        }

        // load application modules
        configFileNames = getModuleConfigFiles(appsHome, prop);
        if (configFileNames.length > 0) {
            String[] configFileUrls = new String[configFileNames.length];
            for (int i = 0; i < configFileNames.length; i++) {
                configFileUrls[i] = "file:" + configFileNames[i];
            }
            context = new FileSystemXmlApplicationContext(configFileUrls,
                                                          context);
            // attach any beans that implement ProcessingElement to the PE
            // Container
            String[] processingElementBeanNames = context.getBeanNamesForType(ProcessingElement.class);
            for (String processingElementBeanName : processingElementBeanNames) {
                Object bean = context.getBean(processingElementBeanName);
                try {
                    Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock");
   
                    if (getS4ClockMethod.getReturnType().equals(Clock.class)) {
                        if (getS4ClockMethod.invoke(bean) == null) {
                            Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class);
                            setS4ClockMethod.invoke(bean, coreContext.getBean("clock"));
                        }
                    }
                }
                catch (NoSuchMethodException mnfe) {
                    // acceptable
                }
                System.out.println("Adding processing element with bean name "
                        + processingElementBeanName + ", id "
                        + ((ProcessingElement) bean).getId());
                peContainer.addProcessor((ProcessingElement) bean);
            }
        } 
    }
View Full Code Here


        }

        // have to compute key value and
        // partition based on hash of that value

        Schema schema = schemaContainer.getSchema(event.getClass());

        if (debug) {
            System.out.println(schema);
        }

        List<CompoundKeyInfo> partitionInfoList = new ArrayList<CompoundKeyInfo>();

        // fast path for single top-level key
        if (fastPath
                || (compoundKeyNames.size() == 1 && compoundKeyNames.get(0)
                                                                    .size() == 1)) {
            String simpleKeyName = compoundKeyNames.get(0).get(0);
            if (debug) {
                System.out.println("Using fast path!");
            }
            fastPath = true;
            KeyInfo keyInfo = new KeyInfo();
            Property property = schema.getProperties().get(simpleKeyName);
            if (property == null) {
                return null;
            }

            Object value = null;
View Full Code Here

        }
        if (property.isList()) {
            List list = (List) value;
            // TODO: handle case where key does not include property of
            // component type
            Schema componentSchema = property.getComponentProperty()
                                             .getSchema();
            int listLength = list.size();
            for (int i = 0; i < listLength; i++) {
                Object listEntry = list.get(i);
                KeyInfo keyInfoForListEntry = keyInfo.copy();
View Full Code Here

            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }

            Schema newEventSchema = schemaContainer.getSchema(newEvent.getClass());

            for (String streamName : eventsToJoin.keySet()) {
                Object partialEvent = eventsToJoin.get(streamName);
                Schema partialEventSchema = schemaContainer.getSchema(partialEvent.getClass());

                List<String> includeFields = eventFields.get(streamName);
                if (includeFields.size() == 1
                        && includeFields.get(0).equals("*")) {
                    for (Property partialEventProperty : partialEventSchema.getProperties()
                                                                           .values()) {
                        copyField(partialEventProperty.getName(),
                                  partialEventSchema,
                                  newEventSchema,
                                  partialEvent,
View Full Code Here

    public void processEvent(Object event) {
        long currentTime = getCurrentTime();
        long maybeCurrentTime = -1;
        if (timestampFields != null) {
            Schema schema = schemaContainer.getSchema(event.getClass());
            String fieldName = timestampFields.get(getStreamName());
            if (fieldName != null) {
                Property property = schema.getProperties().get(fieldName);
                if (property != null
                        && (property.getType().equals(Long.TYPE) || property.getType()
                                                                            .equals(Long.class))) {
                    try {
                        maybeCurrentTime = (Long) property.getGetterMethod()
View Full Code Here

            return;
        }

        keyValue = new ArrayList<Object>();

        Schema schema = schemaContainer.getSchema(event.getClass());

        // get the value for each keyInfo
        for (KeyInfo keyInfo : compoundKeyInfo.getKeyInfoList()) {
            Object value = null;
            Object record = event;
            List<?> list = null;
            Property property = null;
            for (KeyPathElement keyPathElement : keyInfo.getKeyPath()) {
                if (keyPathElement instanceof KeyPathElementIndex) {
                    record = list.get(((KeyPathElementIndex) keyPathElement).getIndex());
                    schema = property.getComponentProperty().getSchema();
                } else {
                    String keyPathElementName = ((KeyPathElementName) keyPathElement).getKeyName();
                    property = schema.getProperties().get(keyPathElementName);
                    value = null;
                    try {
                        value = property.getGetterMethod().invoke(record);
                    } catch (Exception e) {
                        Logger.getLogger("s4").error(e);
View Full Code Here

                JSONObject jsonEventTypeInfo = classInfo.getJSONObject(className);
                int classIndex = (Integer) jsonEventTypeInfo.getInt("classIndex");
                String streamName = jsonEventTypeInfo.getString("streamName");

                Class clazz = Class.forName(className);
                Schema schema = new Schema(clazz);
                eventTypeInfoMap.put(classIndex, new EventTypeInfo(schema,
                                                                   streamName));
            }
        } catch (JSONException je) {
            je.printStackTrace();
View Full Code Here

        long eventTime = -1;
        String streamName = eventWrapper.getStreamName();
        String fieldName = eventClockStreamsMap.get(streamName);
        if (fieldName != null) {
            Object event = eventWrapper.getEvent();
            Schema schema = schemaContainer.getSchema(event.getClass());
            Property property = schema.getProperties().get(fieldName);
            if (property != null
                    && (property.getType().equals(Long.TYPE) || property
                            .getType().equals(Long.class))) {
                try {
                    eventTime = (Long) property.getGetterMethod().invoke(event);
View Full Code Here

            if (debug) {
                System.out.println("Using fast path!");
            }
            fastPath = true;
            KeyInfo keyInfo = new KeyInfo();
            Property property = schema.getProperties().get(simpleKeyName);
            if (property == null) {
                return null;
            }

            Object value = null;
            try {
                value = property.getGetterMethod().invoke(event);
            } catch (Exception e) {
                if (debug) {
                    e.printStackTrace();
                }
            }
View Full Code Here

                                       List<String> keyNameElements,
                                       int elementIndex,
                                       List<KeyInfo> keyInfoList,
                                       KeyInfo keyInfo) {
        String keyElement = keyNameElements.get(elementIndex);
        Property property = schema.getProperties().get(keyElement);
        if (property == null) {
            return null;
        }

        keyInfo.addElementToPath(keyElement);

        Object value = null;
        try {
            value = property.getGetterMethod().invoke(record);
        } catch (Exception e) {
            if (debug) {
                System.out.println("key element is " + keyElement);
                e.printStackTrace();
            }
        }

        if (value == null) {
            return null; // return a null KeyInfo list if we hit a null value
        }
        if (property.isList()) {
            List list = (List) value;
            // TODO: handle case where key does not include property of
            // component type
            Schema componentSchema = property.getComponentProperty()
                                             .getSchema();
            int listLength = list.size();
            for (int i = 0; i < listLength; i++) {
                Object listEntry = list.get(i);
                KeyInfo keyInfoForListEntry = keyInfo.copy();
                keyInfoForListEntry.addElementToPath(i);
                Object partialList = getKeyValues(listEntry,
                                                  componentSchema,
                                                  keyNameElements,
                                                  elementIndex + 1,
                                                  keyInfoList,
                                                  keyInfoForListEntry);
                if (partialList == null) {
                    return null;
                }
            }
        } else if (property.getSchema() != null) {
            return getKeyValues(value,
                                property.getSchema(),
                                keyNameElements,
                                elementIndex + 1,
                                keyInfoList,
                                keyInfo);
        } else {
View Full Code Here

TOP

Related Classes of io.s4.dispatcher.partitioner.KeyInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.