Package org.apache.sling.replication.trigger

Examples of org.apache.sling.replication.trigger.ReplicationTrigger


            seconds = MAX_NUMBER_OF_SECONDS;
        } else if (seconds < 0) {
            seconds = DEFAULT_NUMBER_OF_SECONDS;
        }

        ReplicationTrigger replicationTrigger = request.getResource().adaptTo(ReplicationTrigger.class);

        // setup SSE headers
        response.setContentType("text/event-stream");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Connection", "keep-alive");

        // needed to allow e.g. the JavaScript EventSource API to make a call from author to this server and listen for the events
//        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin")); // allowed origins should be explicitly configured
//        response.setHeader("Access-Control-Allow-Credentials", "true");

        final PrintWriter writer = response.getWriter();

        ReplicationRequestHandler replicationRequestHandler = new ReplicationRequestHandler() {
            public void handle(@Nonnull ReplicationRequest request) {
                writeEvent(writer, request);
            }
        };
        try {
            replicationTrigger.register(replicationRequestHandler);

            try {
                Thread.sleep(seconds * 1000);
            } catch (InterruptedException e) {
                log.error("thread interrupted", e);
            }

            replicationTrigger.unregister(replicationRequestHandler);

        } catch (ReplicationTriggerException e) {
            response.setStatus(400);
            response.getWriter().write("error while (un)registering trigger " + e.toString());
        }
View Full Code Here


                    componentClass = ReplicationAgent.class.getName();
                    componentObject = agent;

                } else if (ReplicationComponentFactory.COMPONENT_TRIGGER.equals(componentType)) {

                    ReplicationTrigger trigger = componentFactory.createComponent(ReplicationTrigger.class, properties, this);

                    componentClass = ReplicationTrigger.class.getName();
                    componentObject = trigger;
                }
View Full Code Here

        DefaultReplicationComponentFactory defaultReplicationComponentFactory = new DefaultReplicationComponentFactory();
        String name = "sample-trigger";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("name", name);
        ReplicationComponentProvider provider = mock(ReplicationComponentProvider.class);
        ReplicationTrigger trigger = mock(ReplicationTrigger.class);
        when(provider.getComponent(ReplicationTrigger.class, name)).thenReturn(trigger);
        ReplicationTrigger component = defaultReplicationComponentFactory.createComponent(ReplicationTrigger.class, properties, provider);
        assertNotNull(component);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.replication.trigger.ReplicationTrigger

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.