public MessageMultiplexer(NotificationConfiguration notifierConfig) { mainQueue = new ArrayBlockingQueue<Notification>(notifierConfig.getQueueSize().intValue()); messageProcessors = new ArrayList<MessageProcessor>(notifierConfig.getNotificators().size()); // Create destination queue, and thread pools one for each processor for (Notificator notificator : notifierConfig.getNotificators()) { messageProcessors.add( new MessageProcessor( notificator.getQueueSize().intValue(), notificator.getProcessorThreads().intValue(), notificator.getMessageFilter(), notificator.getGenericProcessor())); } }
@Override public void run() { try { this.processor.process(this.notification); } catch (Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } }
message.setType(notification.getType() != null ? notification.getType().name() : null); message.setAction( notification.getAction() != null ? notification.getAction().name() : null); message.setTimestamp(new Date()); message.setUser(notification.getUser()); message.setOriginator(InetAddress.getLocalHost().getHostAddress()); message.setProperties(notification.getProperties()); if (notification.getObject() instanceof NamespaceInfo) { NamespaceInfo obj = (NamespaceInfo) notification.getObject(); KombuNamespaceInfo source = new KombuNamespaceInfo(); source.setId(obj.getId()); if (notification.getObject() instanceof WorkspaceInfo) { WorkspaceInfo obj = (WorkspaceInfo) notification.getObject(); KombuWorkspaceInfo source = new KombuWorkspaceInfo(); source.setId(obj.getId()); if (notification.getObject() instanceof LayerInfo) { LayerInfo obj = (LayerInfo) notification.getObject(); KombuLayerInfo source = new KombuLayerInfo(); source.setId(obj.getId()); : ""); if (res.getNativeBoundingBox() != null) { source.setBounds(new Bounds(res.getNativeBoundingBox())); source.setGeographicBunds(new Bounds(res.getLatLonBoundingBox())); if (notification.getObject() instanceof LayerGroupInfo) {
@Test public void catalogAddNamespaces() throws Exception { ReceiverService service = new ReceiverService(2); rc.receive(service); String json = "{'namespace':{ 'prefix':'foo', 'uri':'http://foo.com' }}"; postAsServletResponse("/rest/namespaces", json, "text/json"); List<byte[]> ret = service.getMessages(); assertEquals(2, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); assertEquals("NamespaceInfo", nsMsg.getSource().getType()); KombuMessage wsMsg = Utils.toKombu(ret.get(1)); assertEquals("Catalog", wsMsg.getType()); assertEquals("WorkspaceInfo", wsMsg.getSource().getType()); }
: "/"); factory.setVirtualHost(vHost); factory.setSaslConfig(new CustomSaslConfig()); conn = factory.newConnection(); channel = conn.createChannel();
@Override public SaslMechanism getSaslMechanism(String[] serverMechanisms) { Set<String> server = new HashSet<String>(Arrays.asList(serverMechanisms)); for (String m : mechanisms) { if (server.contains(m)) { if (m.equals("PLAIN")) { return new PlainMechanism(); } else if (m.equals("EXTERNAL")) { return new ExternalMechanism(); } else if (m.equals("ANONYMOUS")) { return new AnonymousMechanism(); } } } return null; } }
@Override public void init(XStream xs) { xs.aliasAttribute(DefaultNotificationProcessor.class, "sender", name); xs.registerLocalConverter( DefaultNotificationProcessor.class, "sender", new SenderConverter(xs.getMapper(), xs.getReflectionProvider(), this)); }
@Override public void init(XStream xs) { xs.aliasAttribute(DefaultNotificationProcessor.class, "encoder", name); xs.registerLocalConverter( DefaultNotificationProcessor.class, "encoder", new EncoderConverter(xs.getMapper(), xs.getReflectionProvider(), this)); }
public void initialize(GeoServer geoServer) throws Exception { XStream xs = new XStream(); List<NotificationXStreamInitializer> xstreamInitializers = GeoServerExtensions.extensions(NotificationXStreamInitializer.class); for (NotificationXStreamInitializer ni : xstreamInitializers) { ni.init(xs); } NotificationConfiguration cfg = getConfiguration(xs); MessageMultiplexer mm = new MessageMultiplexer(cfg); List<INotificationCatalogListener> catalogListeners = GeoServerExtensions.extensions(INotificationCatalogListener.class); for (INotificationCatalogListener cl : catalogListeners) { cl.setMessageMultiplexer(mm); geoServer.getCatalog().addListener(cl); } List<INotificationTransactionListener> transactionListeners = GeoServerExtensions.extensions(INotificationTransactionListener.class); for (INotificationTransactionListener tl : transactionListeners) { tl.setMessageMultiplexer(mm); } (new Thread(mm, THREAD_NAME)).start(); }
@Test public void catalogAddNamespaces() throws Exception { ReceiverService service = new ReceiverService(2); rc.receive(service); String json = "{'namespace':{ 'prefix':'foo', 'uri':'http://foo.com' }}"; postAsServletResponse("/rest/namespaces", json, "text/json"); List<byte[]> ret = service.getMessages(); assertEquals(2, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); assertEquals("NamespaceInfo", nsMsg.getSource().getType()); KombuMessage wsMsg = Utils.toKombu(ret.get(1)); assertEquals("Catalog", wsMsg.getType()); assertEquals("WorkspaceInfo", wsMsg.getSource().getType()); } }
public void receive(ReceiverService service) throws Exception { // let's setup evrything and start listening this.service = service; ConnectionFactory factory = createConnectionFactory(); factory.setSaslConfig(new CustomSaslConfig()); connection = factory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare("testExchange", "fanout"); channel.queueDeclare(QUEUE_NAME, false, true, false, null); channel.queueBind(QUEUE_NAME, "testExchange", "testRouting"); channel.basicConsume(QUEUE_NAME, true, newConsumer(channel)); }
@Test public void catalogChangeLayerStyles() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); String xml = "<style>" + "<name>foo</name>" + "<filename>foo.sld</filename>" + "</style>"; postAsServletResponse("/rest/workspaces/cite/styles", xml); xml = "<layer>" + "<styles>" + "<style>" + "<name>foo</name>" + "<workspace>cite</workspace>" + "</style>" + "</styles>" + "<enabled>true</enabled>" + "</layer>"; putAsServletResponse("/rest/layers/cite:Buildings", xml, "application/xml"); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage updateMsg = Utils.toKombu(ret.get(0)); assertEquals("Catalog", updateMsg.getType()); assertEquals(Notification.Action.Update.name(), updateMsg.getAction()); KombuLayerInfo source = (KombuLayerInfo) updateMsg.getSource(); assertEquals("LayerInfo", source.getType()); assertEquals("foo", source.getStyles()); }
@Test public void catalogAddLayerGroup() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setName("sfLayerGroup"); LayerInfo l = catalog.getLayerByName("cite:Buildings"); lg.getLayers().add(l); lg.getStyles().add(catalog.getStyleByName(StyleInfo.DEFAULT_POLYGON)); lg.setBounds(new ReferencedEnvelope(-180, -90, 180, 90, CRS.decode("EPSG:4326"))); catalog.add(lg); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage groupMsg = Utils.toKombu(ret.get(0)); assertEquals("Catalog", groupMsg.getType()); assertEquals(Notification.Action.Add.name(), groupMsg.getAction()); KombuLayerGroupInfo source = (KombuLayerGroupInfo) groupMsg.getSource(); assertEquals("LayerGroupInfo", source.getType()); assertEquals(1, source.getLayers().size()); KombuLayerSimpleInfo kl = source.getLayers().get(0); assertEquals(l.getName(), kl.getName()); assertEquals(l.getDefaultStyle().getName(), kl.getStyle()); }
@Test public void catalogAddAndDeleteWMSLayer() throws Exception { ReceiverService service = new ReceiverService(3); rc.receive(service); CatalogBuilder cb = new CatalogBuilder(catalog); cb.setWorkspace(catalog.getWorkspaceByName("sf")); WMSStoreInfo wms = cb.buildWMSStore("demo"); wms.setCapabilitiesURL("http://demo.opengeo.org/geoserver/wms?"); catalog.add(wms); addStatesWmsLayer(); assertNotNull(catalog.getResourceByName("sf", "states", WMSLayerInfo.class)); deleteAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/states"); List<byte[]> ret = service.getMessages(); assertEquals(3, ret.size()); KombuMessage addStrMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Add.name(), addStrMsg.getAction()); KombuStoreInfo source1 = (KombuStoreInfo) addStrMsg.getSource(); assertEquals("StoreInfo", source1.getType()); KombuMessage addLayerMsg = Utils.toKombu(ret.get(1)); assertEquals(Notification.Action.Add.name(), addLayerMsg.getAction()); KombuWMSLayerInfo source2 = (KombuWMSLayerInfo) addLayerMsg.getSource(); assertEquals("WMSLayerInfo", source2.getType()); KombuMessage deleteMsg = Utils.toKombu(ret.get(2)); assertEquals("Catalog", deleteMsg.getType()); assertEquals(Notification.Action.Remove.name(), deleteMsg.getAction()); KombuWMSLayerInfo source3 = (KombuWMSLayerInfo) deleteMsg.getSource(); assertEquals("WMSLayerInfo", source3.getType()); assertEquals("states", source3.getName()); catalog.remove(wms); }
@Test public void catalogChangeLayerStyle() throws Exception { ReceiverService service = new ReceiverService(1); rc.receive(service); LayerInfo l = catalog.getLayerByName("cite:Buildings"); assertEquals("Buildings", l.getDefaultStyle().getName()); JSONObject json = (JSONObject) getAsJSON("/rest/layers/cite:Buildings.json"); JSONObject layer = (JSONObject) json.get("layer"); JSONObject style = (JSONObject) layer.get("defaultStyle"); style.put("name", "polygon"); style.put("href", "http://localhost:8080/geoserver/rest/styles/polygon.json"); String updatedJson = json.toString(); putAsServletResponse("/rest/layers/cite:Buildings", updatedJson, "application/json"); List<byte[]> ret = service.getMessages(); assertEquals(1, ret.size()); KombuMessage nsMsg = Utils.toKombu(ret.get(0)); assertEquals(Notification.Action.Update.name(), nsMsg.getAction()); assertEquals("Catalog", nsMsg.getType()); KombuLayerInfo source = (KombuLayerInfo) nsMsg.getSource(); assertEquals("LayerInfo", source.getType()); assertEquals("polygon", source.getDefaultStyle()); }
@Test public void catalogAddCoverage() throws Exception { ReceiverService service = new ReceiverService(4); rc.receive(service); addCoverageStore(); NamespaceInfo ns = catalog.getFactory().createNamespace(); ns.setPrefix("bar"); ns.setURI("http://bar"); catalog.add(ns); CoverageInfo ft = catalog.getFactory().createCoverage(); ft.setName("foo"); ft.setNamespace(ns); ft.setStore(catalog.getCoverageStoreByName("acme", "foostore")); catalog.add(ft); List<byte[]> ret = service.getMessages(); assertEquals(4, ret.size()); KombuMessage coverageMsg = Utils.toKombu(ret.get(3)); assertEquals("Catalog", coverageMsg.getType()); assertEquals(Notification.Action.Add.name(), coverageMsg.getAction()); KombuCoverageInfo source = (KombuCoverageInfo) coverageMsg.getSource(); assertEquals("CoverageInfo", source.getType()); assertEquals(ft.getName(), source.getName()); }