This is an automated email from the ASF dual-hosted git repository.

cschneider pushed a commit to branch SLING-11692
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git

commit c196d39b99e8c1deb0fa1023a3c811d0733fcba8
Author: Christian Schneider <[email protected]>
AuthorDate: Tue Nov 22 14:11:37 2022 +0100

    SLING-11692 - Remove unused JMX bean from DistPublisher
---
 .../journal/impl/publisher/DistPublisherJMX.java   | 103 --------------
 .../impl/publisher/DistPublisherJMXMBean.java      |  28 ----
 .../impl/publisher/DistributionPublisher.java      |  16 +--
 .../impl/publisher/DistPublisherJMXTest.java       | 154 ---------------------
 4 files changed, 1 insertion(+), 300 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMX.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMX.java
deleted file mode 100644
index 48e69a5..0000000
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMX.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.distribution.journal.impl.publisher;
-
-import java.util.Set;
-
-import javax.management.MBeanException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.StandardMBean;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.CompositeDataSupport;
-import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.OpenDataException;
-import javax.management.openmbean.OpenType;
-import javax.management.openmbean.SimpleType;
-import javax.management.openmbean.TabularData;
-import javax.management.openmbean.TabularDataSupport;
-import javax.management.openmbean.TabularType;
-
-import org.apache.sling.distribution.journal.impl.discovery.DiscoveryService;
-import org.apache.sling.distribution.journal.impl.discovery.State;
-import org.apache.sling.distribution.queue.DistributionQueueEntry;
-import org.apache.sling.distribution.queue.spi.DistributionQueue;
-
-class DistPublisherJMX extends StandardMBean implements DistPublisherJMXMBean {
-
-    private static final String COL_ID = "ID";
-    private static final String COL_OFFSET = "offset";
-    private String pubAgentName;
-    private DiscoveryService discoveryService;
-    private DistributionPublisher distPublisher;
-
-    protected DistPublisherJMX(String pubAgentName, 
-            DiscoveryService discoveryService,
-            DistributionPublisher distPublisher
-            ) throws NotCompliantMBeanException {
-        super(DistPublisherJMXMBean.class);
-        this.pubAgentName = pubAgentName;
-        this.discoveryService = discoveryService;
-        this.distPublisher = distPublisher;
-    }
-
-    @Override
-    public TabularData getOffsetPerSubscriber() throws MBeanException {
-        try {
-            String[] itemNames = new String[] {COL_ID, COL_OFFSET};
-            OpenType<?>[] itemTypes = new OpenType[]{SimpleType.STRING, 
SimpleType.LONG};
-            CompositeType rowType = new CompositeType("Offsets", "Offsets by 
sub agent", itemNames, itemNames, itemTypes);
-            TabularType type = new TabularType("type", "desc", rowType, new 
String[] {COL_ID});
-            TabularDataSupport table = new TabularDataSupport(type);
-            Set<State> subscribedAgents = 
discoveryService.getTopologyView().getSubscribedAgents(pubAgentName);
-            for (State state : subscribedAgents) {
-                CompositeData row = new CompositeDataSupport(rowType, 
itemNames, new Object[] { 
-                        state.getSubAgentId(), 
-                        state.getOffset()
-                        });
-                table.put(row);
-            }
-            return table;
-        } catch (OpenDataException e) {
-            throw new MBeanException(e);
-        }
-    }
-    
-    @Override
-    public TabularData getQueue(String queueName) throws MBeanException {
-        try {
-            String[] itemNames = new String[] {COL_ID, COL_OFFSET};
-            OpenType<?>[] itemTypes = new OpenType[]{SimpleType.STRING, 
SimpleType.LONG};
-            CompositeType rowType = new CompositeType("Offsets", "Queue 
Offsets", itemNames, itemNames, itemTypes);
-            TabularType type = new TabularType("type", "desc", rowType, new 
String[] {COL_ID});
-            TabularDataSupport table = new TabularDataSupport(type);
-            DistributionQueue queue = distPublisher.getQueue(queueName);
-            if (queue != null) {
-                for (DistributionQueueEntry item : queue.getEntries(0, 1000)) {
-                    CompositeData row = new CompositeDataSupport(rowType, 
itemNames,
-                            new Object[] { item.getId(), 
item.getItem().get(COL_OFFSET)});
-                    table.put(row);
-                }
-            }
-            return table;
-        } catch (OpenDataException e) {
-            throw new MBeanException(e);
-        }
-    }
-    
-}
\ No newline at end of file
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXMBean.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXMBean.java
deleted file mode 100644
index 96a1485..0000000
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXMBean.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.distribution.journal.impl.publisher;
-
-import javax.management.MBeanException;
-import javax.management.openmbean.TabularData;
-
-public interface DistPublisherJMXMBean {
-    TabularData getOffsetPerSubscriber() throws MBeanException;
-
-    TabularData getQueue(String queueName) throws MBeanException;
-}
\ No newline at end of file
diff --git 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
 
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
index ff98ce9..e9d2504 100644
--- 
a/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
+++ 
b/src/main/java/org/apache/sling/distribution/journal/impl/publisher/DistributionPublisher.java
@@ -36,7 +36,6 @@ import java.util.function.ToLongFunction;
 
 import javax.annotation.Nonnull;
 import javax.annotation.ParametersAreNonnullByDefault;
-import javax.management.NotCompliantMBeanException;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.sling.distribution.DistributionResponseInfo;
@@ -48,7 +47,6 @@ import 
org.apache.sling.distribution.journal.queue.PubQueueProvider;
 import org.apache.sling.distribution.journal.shared.DefaultDistributionLog;
 import 
org.apache.sling.distribution.journal.shared.DistributionLogEventListener;
 import org.apache.sling.distribution.journal.shared.DistributionMetricsService;
-import org.apache.sling.distribution.journal.shared.JMXRegistration;
 import org.apache.sling.distribution.journal.shared.Topics;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.distribution.DistributionRequest;
@@ -131,8 +129,6 @@ public class DistributionPublisher implements 
DistributionAgent {
 
     private Consumer<PackageMessage> sender;
 
-    private JMXRegistration reg;
-
     private Closeable statusPoller;
 
     private DistributionLogEventListener distributionLogEventListener;
@@ -155,7 +151,6 @@ public class DistributionPublisher implements 
DistributionAgent {
         pkgType = packageBuilder.getType();
 
         distributionLogEventListener = new 
DistributionLogEventListener(context, log, pubAgentName);
-        reg = registerJMXBean();
         String subscriberCountName = PUB_COMPONENT + 
".subscriber_count;pub_name=" + pubAgentName;
         distributionMetricsService.createGauge(subscriberCountName, 
this::getNumSubscribedAgents);
         
@@ -173,7 +168,7 @@ public class DistributionPublisher implements 
DistributionAgent {
 
     @Deactivate
     public void deactivate() {
-        IOUtils.closeQuietly(statusPoller, distributionLogEventListener, reg);
+        IOUtils.closeQuietly(statusPoller, distributionLogEventListener);
         componentReg.unregister();
         String msg = format("Stopped Publisher agent %s with packageBuilder 
%s, queuedTimeout %s",
                 pubAgentName, pkgType, queuedTimeout);
@@ -242,15 +237,6 @@ public class DistributionPublisher implements 
DistributionAgent {
         return 
discoveryService.getTopologyView().getSubscribedAgentIds().size();
     }
 
-    private JMXRegistration registerJMXBean() {
-        try {
-            DistPublisherJMX bean = new DistPublisherJMX(pubAgentName, 
discoveryService, this);
-            return new JMXRegistration(bean, "agent", pubAgentName);
-        } catch (NotCompliantMBeanException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     private DistributionResponse execute(ResourceResolver resourceResolver,
                                          DistributionRequest request,
                                          ToLongFunction<PackageMessage> sender)
diff --git 
a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXTest.java
 
b/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXTest.java
deleted file mode 100644
index 5ba2231..0000000
--- 
a/src/test/java/org/apache/sling/distribution/journal/impl/publisher/DistPublisherJMXTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.sling.distribution.journal.impl.publisher;
-
-import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
-import static java.util.Arrays.asList;
-import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import javax.management.MBeanException;
-import javax.management.MBeanServer;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-import javax.management.openmbean.TabularDataSupport;
-
-import org.apache.sling.distribution.journal.impl.discovery.DiscoveryService;
-import org.apache.sling.distribution.journal.impl.discovery.State;
-import org.apache.sling.distribution.journal.impl.discovery.TopologyView;
-import org.apache.sling.distribution.journal.shared.JMXRegistration;
-import org.apache.sling.distribution.queue.DistributionQueueEntry;
-import org.apache.sling.distribution.queue.DistributionQueueItem;
-import org.apache.sling.distribution.queue.DistributionQueueItemState;
-import org.apache.sling.distribution.queue.DistributionQueueItemStatus;
-import org.apache.sling.distribution.queue.spi.DistributionQueue;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-
-@SuppressWarnings("rawtypes")
-public class DistPublisherJMXTest {
-
-    private static final String SUB1_ID = "sling1sub1";
-    private static final String TYPE = "PublishAgent";
-    private static final String AGENT1 = "agent1";
-    private static final String AGENT2 = "agent2";
-
-    @Mock
-    DiscoveryService discoveryService;
-    
-    @Mock
-    private DistributionPublisher distPublisher;
-
-    @Mock
-    private DistributionQueue queue;
-
-    private DistPublisherJMX bean;
-
-    private JMXRegistration reg;
-    
-    
-    @Before
-    public void before() throws NotCompliantMBeanException {
-        MockitoAnnotations.initMocks(this);
-        Set<State> states = new HashSet<>(Arrays.asList(
-                new State(AGENT1, "sling1_sub1", 0, 10, 0, -1, false),
-                new State(AGENT1, "sling2_sub1", 0, 15, 0, -1, false),
-                new State(AGENT2, "sling2_sub1", 0,  5, 0, -1, false)
-                ));
-        TopologyView topologyView = new TopologyView(states);
-        when(discoveryService.getTopologyView()).thenReturn(topologyView);
-        
-        DistributionQueueEntry entry1 = createQueueEntry();
-        List<DistributionQueueEntry> items = asList(entry1);
-        when(queue.getEntries(Mockito.anyInt(), 
Mockito.anyInt())).thenReturn(items);
-        when(distPublisher.getQueue(SUB1_ID + "-error")).thenReturn(queue);
-        bean = new DistPublisherJMX(AGENT1, discoveryService, distPublisher);
-        reg = new JMXRegistration(bean, TYPE, AGENT1);
-    }
-
-    private DistributionQueueEntry createQueueEntry() {
-        Map<String, Object> content = new HashMap<>();
-        content.put("offset", 10L);
-        DistributionQueueItem item = new DistributionQueueItem("packageid", 
content);
-        DistributionQueueItemStatus status = new 
DistributionQueueItemStatus(DistributionQueueItemState.ERROR, "name");
-        return new DistributionQueueEntry("id", item, status);
-    }
-    
-    @After
-    public void after() throws IOException {
-        reg.close();
-    }
-    
-    @Test
-    public void testCallOffsetPerSubScriber() throws MBeanException {
-        TabularData table = bean.getOffsetPerSubscriber();
-        checkTable(idToOffset(table));
-    }
-    
-    @Test
-    public void testCallQueue() throws MBeanException {
-        TabularData table = bean.getQueue(SUB1_ID + "-error");
-        checkQueueTable(table);
-    }
-
-    @Test
-    public void testJMXOffsetPerSubScriber() throws Exception {
-        MBeanServer mbeanServer = getPlatformMBeanServer();
-        ObjectName name = new ObjectName("org.apache.sling.distribution:type=" 
+ TYPE + ",id=" + AGENT1);
-        TabularData table = (TabularData) mbeanServer.getAttribute(name, 
"OffsetPerSubscriber");
-        checkTable(idToOffset(table));
-    }
-
-       private void checkTable(Map table) {
-        assertTrue(table.containsKey("sling1_sub1"));
-        assertThat(table.get("sling1_sub1"), equalTo(10L));
-    }
-
-    private void checkQueueTable(TabularData table) {
-        CompositeData row1 = (CompositeData)table.values().iterator().next();
-        assertThat(row1.get("ID"), equalTo("id"));
-        assertThat(row1.get("offset"), equalTo(10L));
-    }
-
-    private Map idToOffset(TabularData table) {
-        return ((TabularDataSupport) table).entrySet().stream()
-                .collect(Collectors.toMap(
-                a -> ((CompositeData)a.getValue()).get("ID"),
-                b -> ((CompositeData)b.getValue()).get("offset")));
-    }
-
-    
-}

Reply via email to