Search in sources :

Example 1 with FileLogger

use of org.kie.workbench.common.services.shared.kmodule.FileLogger in project kie-wb-common by kiegroup.

the class FileLoggerConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    FileLogger logger = (FileLogger) value;
    writer.addAttribute("name", logger.getName());
    writer.addAttribute("file", logger.getFile());
    writer.addAttribute("threaded", Boolean.toString(logger.isThreaded()));
    writer.addAttribute("interval", Integer.toString(logger.getInterval()));
}
Also used : FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger)

Example 2 with FileLogger

use of org.kie.workbench.common.services.shared.kmodule.FileLogger in project kie-wb-common by kiegroup.

the class FileLoggerConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final FileLogger logger = new FileLogger();
    logger.setName(reader.getAttribute("name"));
    logger.setFile(reader.getAttribute("file"));
    logger.setThreaded(Boolean.parseBoolean(reader.getAttribute("threaded")));
    logger.setInterval(Integer.parseInt(reader.getAttribute("interval")));
    return logger;
}
Also used : FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger)

Example 3 with FileLogger

use of org.kie.workbench.common.services.shared.kmodule.FileLogger in project kie-wb-common by kiegroup.

the class KSessionConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final KSessionModel kSession = new KSessionModel();
    kSession.setName(reader.getAttribute("name"));
    kSession.setDefault("true".equals(reader.getAttribute("default")));
    String kSessionType = reader.getAttribute("type");
    kSession.setType(kSessionType != null ? kSessionType : "stateful");
    String clockType = reader.getAttribute("clockType");
    if (clockType != null) {
        kSession.setClockType(ClockTypeOption.get(clockType));
    }
    String scope = reader.getAttribute("scope");
    if (scope != null) {
        kSession.setScope(scope);
    }
    readNodes(reader, new AbstractXStreamConverter.NodeReader() {

        public void onNode(HierarchicalStreamReader reader, String name, String value) {
            if ("listeners".equals(name)) {
                while (reader.hasMoreChildren()) {
                    reader.moveDown();
                    kSession.getListeners().add(readObject(reader, context, ListenerModel.class));
                    reader.moveUp();
                }
            } else if ("workItemHandlers".equals(name)) {
                kSession.getWorkItemHandelerModels().addAll(readObjectList(reader, context, WorkItemHandlerModel.class));
            } else if ("consoleLogger".equals(name)) {
                kSession.setLogger(readObject(reader, context, ConsoleLogger.class));
            } else if ("fileLogger".equals(name)) {
                kSession.setLogger(readObject(reader, context, FileLogger.class));
            }
        }
    });
    return kSession;
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) WorkItemHandlerModel(org.guvnor.common.services.project.model.WorkItemHandlerModel) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger) AbstractXStreamConverter(org.drools.core.util.AbstractXStreamConverter)

Example 4 with FileLogger

use of org.kie.workbench.common.services.shared.kmodule.FileLogger in project kie-wb-common by kiegroup.

the class KSessionConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    KSessionModel kSession = (KSessionModel) value;
    writer.addAttribute("name", kSession.getName());
    writer.addAttribute("type", kSession.getType());
    writer.addAttribute("default", Boolean.toString(kSession.isDefault()));
    if (kSession.getClockType() != null) {
        writer.addAttribute("clockType", kSession.getClockType().getClockTypeAsString());
    }
    if (kSession.getScope() != null) {
        writer.addAttribute("scope", kSession.getScope().toString());
    }
    writeObjectList(writer, context, "workItemHandlers", "workItemHandler", kSession.getWorkItemHandelerModels());
    if (kSession.getLogger() instanceof ConsoleLogger) {
        writeObject(writer, context, "consoleLogger", kSession.getLogger());
    } else if (kSession.getLogger() instanceof FileLogger) {
        writeObject(writer, context, "fileLogger", kSession.getLogger());
    }
    if (!kSession.getListeners().isEmpty()) {
        writer.startNode("listeners");
        for (ListenerModel listener : kSession.getListeners()) {
            writeObject(writer, context, listener.getKind().toString(), listener);
        }
        writer.endNode();
    }
}
Also used : ListenerModel(org.kie.workbench.common.services.shared.kmodule.ListenerModel) ConsoleLogger(org.kie.workbench.common.services.shared.kmodule.ConsoleLogger) KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger)

Example 5 with FileLogger

use of org.kie.workbench.common.services.shared.kmodule.FileLogger in project kie-wb-common by kiegroup.

the class KModuleContentHandlerTest method testBasic.

@Test
public void testBasic() throws Exception {
    final KModuleContentHandler kModuleContentHandler = new KModuleContentHandler();
    final KModuleModel model = kModuleContentHandler.toModel(readResource("simpleKModule.xml"));
    assertNotNull(model);
    assertEquals(1, model.getKBases().size());
    final KBaseModel kBaseModel = model.getKBases().get("org.kie.example1");
    assertNotNull(kBaseModel);
    assertEquals(1, kBaseModel.getKSessions().size());
    final KSessionModel kSessionModel = kBaseModel.getKSessions().get(0);
    assertEquals("ksession1", kSessionModel.getName());
    assertEquals("stateful", kSessionModel.getType());
    assertTrue(kSessionModel.isDefault());
    assertEquals(ClockTypeOption.REALTIME, kSessionModel.getClockType());
    assertTrue(kSessionModel.getLogger() instanceof FileLogger);
    final FileLogger logger = (FileLogger) kSessionModel.getLogger();
    assertEquals("response-builder_filelogger", logger.getName());
    assertEquals("/tmp/response-builder_filelogger.log", logger.getFile());
    assertTrue(logger.isThreaded());
    assertEquals(1500, logger.getInterval());
    final String xml = kModuleContentHandler.toString(model);
    assertTrue(xml.contains("<kbase name=\"org.kie.example1\" default=\"false\" eventProcessingMode=\"stream\" equalsBehavior=\"identity\">"));
    assertTrue(xml.contains("<ksession name=\"ksession1\" type=\"stateful\" default=\"true\" clockType=\"realtime\">"));
    assertTrue(xml.contains("<fileLogger name=\"response-builder_filelogger\" file=\"/tmp/response-builder_filelogger.log\" threaded=\"true\" interval=\"1500\"/>"));
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) FileLogger(org.kie.workbench.common.services.shared.kmodule.FileLogger) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel) KModuleModel(org.kie.workbench.common.services.shared.kmodule.KModuleModel) Test(org.junit.Test)

Aggregations

FileLogger (org.kie.workbench.common.services.shared.kmodule.FileLogger)5 KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 AbstractXStreamConverter (org.drools.core.util.AbstractXStreamConverter)1 WorkItemHandlerModel (org.guvnor.common.services.project.model.WorkItemHandlerModel)1 Test (org.junit.Test)1 ConsoleLogger (org.kie.workbench.common.services.shared.kmodule.ConsoleLogger)1 KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)1 KModuleModel (org.kie.workbench.common.services.shared.kmodule.KModuleModel)1 ListenerModel (org.kie.workbench.common.services.shared.kmodule.ListenerModel)1