[Git][java-team/libsejda-eventstudio-java][upstream] New upstream version 3.0.4
Markus Koschany (@apo)
gitlab at salsa.debian.org
Fri Feb 11 11:14:37 GMT 2022
Markus Koschany pushed to branch upstream at Debian Java Maintainers / libsejda-eventstudio-java
Commits:
733f26ad by Markus Koschany at 2022-02-11T12:11:10+01:00
New upstream version 3.0.4
- - - - -
22 changed files:
- + .github/workflows/build.yml
- + .github/workflows/release.yml
- − .travis.yml
- README.md
- pom.xml
- + src/main/java/module-info.java
- src/main/java/org/pdfsam/eventstudio/Annotations.java
- src/main/java/org/pdfsam/eventstudio/DefaultEventStudio.java
- src/main/java/org/pdfsam/eventstudio/Entity.java
- src/main/java/org/pdfsam/eventstudio/Envelope.java
- src/main/java/org/pdfsam/eventstudio/EventStudio.java
- src/main/java/org/pdfsam/eventstudio/Listener.java
- src/main/java/org/pdfsam/eventstudio/Listeners.java
- src/main/java/org/pdfsam/eventstudio/ReferenceStrength.java
- src/main/java/org/pdfsam/eventstudio/Station.java
- src/main/java/org/pdfsam/eventstudio/Stations.java
- src/main/java/org/pdfsam/eventstudio/Supervisor.java
- src/main/java/org/pdfsam/eventstudio/util/ReflectionUtils.java
- src/main/java/org/pdfsam/eventstudio/util/RequireUtils.java
- src/main/java/org/pdfsam/eventstudio/util/StringUtils.java
- src/test/java/org/pdfsam/eventstudio/AnnotationsTest.java
- src/test/java/org/pdfsam/eventstudio/util/ReflectionUtilsTest.java
Changes:
=====================================
.github/workflows/build.yml
=====================================
@@ -0,0 +1,22 @@
+name: build
+
+on: [push]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: ['11', '17']
+ name: JDK ${{ matrix.java }}
+
+ steps:
+ - uses: actions/checkout at v2
+ - name: Set up JDK
+ uses: actions/setup-java at v2
+ with:
+ java-version: ${{ matrix.java }}
+ distribution: 'temurin'
+ cache: 'maven'
+ - name: Build with Maven
+ run: mvn --batch-mode --update-snapshots verify
\ No newline at end of file
=====================================
.github/workflows/release.yml
=====================================
@@ -0,0 +1,35 @@
+name: release
+
+on:
+ push:
+ tags:
+ - '*'
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ name: release
+
+ steps:
+ - name: Checkout repo
+ uses: actions/checkout at v2
+ - name: Import GPG key
+ id: import_gpg
+ uses: crazy-max/ghaction-import-gpg at v4
+ with:
+ gpg_private_key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
+ passphrase: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
+ - name: Set up JDK
+ uses: actions/setup-java at v2
+ with:
+ java-version: 11
+ distribution: 'temurin'
+ server-id: pdfsam-ossrh
+ server-username: OSSRH_USERNAME
+ server-password: OSSRH_TOKEN
+ cache: 'maven'
+ - name: Publish to Central
+ env:
+ OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
+ OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
+ run: mvn --no-transfer-progress --batch-mode -Prelease deploy
=====================================
.travis.yml deleted
=====================================
@@ -1,5 +0,0 @@
-language: java
-sudo: false
-dist: xenial
-jdk:
- - openjdk8
\ No newline at end of file
=====================================
README.md
=====================================
@@ -1,7 +1,7 @@
EventStudio
=====================
-[![Build Status](https://travis-ci.org/torakiki/event-studio.png?branch=master)](https://travis-ci.org/torakiki/event-studio)
+![Build Status](https://github.com/torakiki/event-studio/actions/workflows/build.yml/badge.svg)
[![License](http://img.shields.io/badge/license-APLv2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
EventStudio is yet another pure Java event bus implementation providing pub/sub pattern with events queue capabilities for intra-jvm event communication.
@@ -32,6 +32,7 @@ The solution I found was to mimic a network of radio stations. For those familia
Features/Characteristics
---------
++ Branch 2 requires JDK 8 or higher, Branch 3 requires JDK 11 or higher
+ Minimal dependencies ([slf4j](http://www.slf4j.org/))
+ Thread safe
+ Fully unit tested
=====================================
pom.xml
=====================================
@@ -1,196 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.pdfsam</groupId>
- <artifactId>eventstudio</artifactId>
- <packaging>jar</packaging>
- <name>eventstudio</name>
- <version>2.0.1</version>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.pdfsam</groupId>
+ <artifactId>eventstudio</artifactId>
+ <packaging>jar</packaging>
+ <name>eventstudio</name>
+ <version>3.0.4</version>
- <description>A simple even bus implementation providing pub/sub event exchange between components</description>
- <url>https://pdfsam.org</url>
+ <description>A simple even bus implementation providing pub/sub event exchange between components</description>
+ <url>https://pdfsam.org</url>
- <issueManagement>
- <system>GitHub</system>
- <url>https://github.com/torakiki/event-studio/</url>
- </issueManagement>
+ <issueManagement>
+ <system>GitHub</system>
+ <url>https://github.com/torakiki/event-studio/</url>
+ </issueManagement>
- <organization>
- <name>Sober Lemur S.a.s. di Vacondio Andrea</name>
- <url>https://pdfsam.org</url>
- </organization>
+ <organization>
+ <name>Sober Lemur S.a.s. di Vacondio Andrea</name>
+ <url>https://pdfsam.org</url>
+ </organization>
- <licenses>
- <license>
- <name>Apache License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0</url>
- <distribution>repo</distribution>
- <comments>ASLv2</comments>
- </license>
- </licenses>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ <distribution>repo</distribution>
+ <comments>ASLv2</comments>
+ </license>
+ </licenses>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
- <scm>
- <connection>scm:git:git at github.com:torakiki/event-studio.git</connection>
- <developerConnection>scm:git:git at github.com:torakiki/event-studio.git</developerConnection>
- <url>scm:git:git at github.com:torakiki/event-studio.git</url>
- <tag>v2.0.1</tag>
- </scm>
+ <scm>
+ <connection>scm:git:git at github.com:torakiki/event-studio.git</connection>
+ <developerConnection>scm:git:git at github.com:torakiki/event-studio.git</developerConnection>
+ <url>scm:git:git at github.com:torakiki/event-studio.git</url>
+ <tag>v3.0.4</tag>
+ </scm>
- <developers>
- <developer>
- <id>torakiki</id>
- <name>Andrea Vacondio</name>
- <email>andrea.vacondio at gmail.com</email>
- </developer>
- </developers>
+ <developers>
+ <developer>
+ <id>torakiki</id>
+ <name>Andrea Vacondio</name>
+ <email>andrea.vacondio at gmail.com</email>
+ </developer>
+ </developers>
- <distributionManagement>
- <snapshotRepository>
- <id>sonatype-nexus-snapshots</id>
- <url>https://oss.sonatype.org/content/repositories/snapshots</url>
- </snapshotRepository>
- <repository>
- <id>pdfsam-ossrh</id>
- <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
- </repository>
- </distributionManagement>
+ <distributionManagement>
+ <snapshotRepository>
+ <id>sonatype-nexus-snapshots</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ </snapshotRepository>
+ <repository>
+ <id>pdfsam-ossrh</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ </distributionManagement>
- <profiles>
- <profile>
- <id>release</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>3.2.0</version>
- <executions>
- <execution>
- <id>attach-javadocs</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <version>3.0.0-M1</version>
- <configuration>
- <tagNameFormat>v@{project.version}</tagNameFormat>
- <localCheckout>true</localCheckout>
- <preparationGoals>clean install</preparationGoals>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <version>1.6</version>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.sonatype.plugins</groupId>
- <artifactId>nexus-staging-maven-plugin</artifactId>
- <version>1.6.8</version>
- <extensions>true</extensions>
- <configuration>
- <serverId>pdfsam-ossrh</serverId>
- <nexusUrl>https://oss.sonatype.org/</nexusUrl>
- <autoReleaseAfterClose>true</autoReleaseAfterClose>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>3.2.0</version>
+ <configuration>
+ <doclint>all,-missing</doclint>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>3.0.0-M4</version>
+ <configuration>
+ <tagNameFormat>v@{project.version}</tagNameFormat>
+ <localCheckout>true</localCheckout>
+ <preparationGoals>clean install</preparationGoals>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>3.0.1</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.8</version>
+ <extensions>true</extensions>
+ <configuration>
+ <serverId>pdfsam-ossrh</serverId>
+ <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+ <autoReleaseAfterClose>true</autoReleaseAfterClose>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.8.1</version>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>3.2.0</version>
- <configuration>
- <archive>
- <manifestEntries>
- <Built-By>Sober Lemur S.a.s.</Built-By>
- <Automatic-Module-Name>org.pdfsam.eventstudio</Automatic-Module-Name>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <version>3.2.0</version>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>3.0.0-M5</version>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.30</version>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.2.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>3.7.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- <version>1.3</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <release>11</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.2.0</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Built-By>Sober Lemur S.a.s.</Built-By>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>3.2.0</version>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>3.0.0-M5</version>
+ <configuration>
+ <argLine>--enable-preview --add-opens org.pdfsam.eventstudio/org.pdfsam.eventstudio=ALL-UNNAMED</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.32</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.2.9</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>4.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>5.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.vintage</groupId>
+ <artifactId>junit-vintage-engine</artifactId>
+ <version>5.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
=====================================
src/main/java/module-info.java
=====================================
@@ -0,0 +1,23 @@
+/*
+ * This file is part of the EventStudio source code
+ * Created on 22/dec/2021
+ * Copyright 2021 by Sober Lemur S.a.s di Vacondio Andrea (info at soberlemur.com).
+ *
+ * Licensed 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.
+ */
+module org.pdfsam.eventstudio {
+ exports org.pdfsam.eventstudio;
+ exports org.pdfsam.eventstudio.annotation;
+ exports org.pdfsam.eventstudio.exception;
+ requires org.slf4j;
+}
\ No newline at end of file
=====================================
src/main/java/org/pdfsam/eventstudio/Annotations.java
=====================================
@@ -1,19 +1,19 @@
-/*
+/*
* This file is part of the EventStudio source code
* Created on 15/nov/2013
* Copyright 2020 by Sober Lemur S.a.s di Vacondio Andrea (info at pdfsam.org).
- *
- * Licensed 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
+ *
+ * Licensed 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.
+ * 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.pdfsam.eventstudio;
@@ -39,9 +39,8 @@ import org.slf4j.LoggerFactory;
/**
* Utility methods processing beans to find annotated method or fields and register reflective listeners.
- *
+ *
* @author Andrea Vacondio
- *
*/
final class Annotations {
@@ -68,8 +67,7 @@ final class Annotations {
}
/**
- * @param bean
- * @return a list containing all the public methods (inherited and not) and all the private, package and protected (not inherited)
+ * @return a list containing all the public methods (inherited and not) and all the private, package and protected (not inherited) methods of the given bean
*/
private static List<Method> getMethods(Object bean) {
List<Method> methods = new LinkedList<>(Arrays.asList(bean.getClass().getMethods()));
@@ -111,9 +109,9 @@ final class Annotations {
}
/**
- * @param bean
- * @throws IllegalAccessException
+ * @param bean the bean to be searched
* @return a String value with the name of the station if an annotated field was found, null otherwise.
+ * @throws IllegalAccessException
*/
private static String getStationNameFromFieldIfAny(Object bean) throws IllegalAccessException {
for (Field field : bean.getClass().getDeclaredFields()) {
@@ -131,20 +129,15 @@ final class Annotations {
/**
* Holds metadata retrieved from the reflective inspection of a bean
- *
+ *
* @author Andrea Vacondio
- *
*/
static class ReflectiveMetadata {
private String station;
- private Map<String, List<ReflectiveListenerDescriptor>> descriptors = new HashMap<>();
+ private final Map<String, List<ReflectiveListenerDescriptor>> descriptors = new HashMap<>();
private void put(String station, ReflectiveListenerDescriptor descriptor) {
- List<ReflectiveListenerDescriptor> current = descriptors.get(station);
- if (current == null) {
- current = new ArrayList<>();
- descriptors.put(station, current);
- }
+ List<ReflectiveListenerDescriptor> current = descriptors.computeIfAbsent(station, k -> new ArrayList<>());
current.add(descriptor);
}
@@ -160,14 +153,13 @@ final class Annotations {
/**
* Descriptor of a reflective listener holding information needed to create the listener
- *
+ *
* @author Andrea Vacondio
- *
*/
static class ReflectiveListenerDescriptor {
- private EventListener listenerAnnotation;
- private Method method;
+ private final EventListener listenerAnnotation;
+ private final Method method;
public ReflectiveListenerDescriptor(EventListener listenerAnnotation, Method method) {
this.listenerAnnotation = listenerAnnotation;
=====================================
src/main/java/org/pdfsam/eventstudio/DefaultEventStudio.java
=====================================
@@ -86,9 +86,7 @@ public class DefaultEventStudio implements EventStudio {
String station = defaultString(metadata.getStation(), HIDDEN_STATION);
stations.getStation(defaultString(current.getKey(), station)).addAll(bean, current.getValue());
}
- } catch (IllegalAccessException e) {
- throw new EventStudioException("An error occurred processing the input bean", e);
- } catch (InvocationTargetException e) {
+ } catch (IllegalAccessException | InvocationTargetException e) {
throw new EventStudioException("An error occurred processing the input bean", e);
}
@@ -137,7 +135,6 @@ public class DefaultEventStudio implements EventStudio {
/**
* Adds a {@link Supervisor} to the hidden station, hiding the station abstraction.
*
- * @param supervisor
* @see EventStudio#supervisor(Supervisor, String)
* @see DefaultEventStudio#HIDDEN_STATION
*/
=====================================
src/main/java/org/pdfsam/eventstudio/Entity.java
=====================================
@@ -41,8 +41,8 @@ interface Entity<T> {
*
* @param <T>
*/
- static class ReferencedEntity<T> implements Entity<T> {
- private Reference<T> reference;
+ class ReferencedEntity<T> implements Entity<T> {
+ private final Reference<T> reference;
ReferencedEntity(Reference<T> reference) {
requireNotNull(reference);
@@ -61,8 +61,8 @@ interface Entity<T> {
*
* @param <T>
*/
- static class StrongEntity<T> implements Entity<T> {
- private T referent;
+ class StrongEntity<T> implements Entity<T> {
+ private final T referent;
StrongEntity(T referent) {
this.referent = referent;
=====================================
src/main/java/org/pdfsam/eventstudio/Envelope.java
=====================================
@@ -27,7 +27,7 @@ import static org.pdfsam.eventstudio.util.RequireUtils.requireNotNull;
*/
class Envelope {
private boolean notified = false;
- private Object event;
+ private final Object event;
Envelope(Object event) {
requireNotNull(event);
=====================================
src/main/java/org/pdfsam/eventstudio/EventStudio.java
=====================================
@@ -80,7 +80,6 @@ public interface EventStudio {
/**
* Discovers annotated method on the the given bean and adds them as {@link Listener}s
*
- * @param bean
* @see org.pdfsam.eventstudio.annotation.EventListener
* @see org.pdfsam.eventstudio.annotation.EventStation
*/
=====================================
src/main/java/org/pdfsam/eventstudio/Listener.java
=====================================
@@ -28,8 +28,6 @@ public interface Listener<T> {
/**
* Notify the listener of the given event
- *
- * @param event
*/
void onEvent(T event);
}
=====================================
src/main/java/org/pdfsam/eventstudio/Listeners.java
=====================================
@@ -1,19 +1,19 @@
-/*
+/*
* This file is part of the EventStudio source code
* Created on 11/nov/2013
* Copyright 2020 by Sober Lemur S.a.s di Vacondio Andrea (info at pdfsam.org).
- *
- * Licensed 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
+ *
+ * Licensed 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.
+ * 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.pdfsam.eventstudio;
@@ -39,259 +39,241 @@ import org.slf4j.LoggerFactory;
/**
* A thread-safe holder for the listeners
- *
+ *
* @author Andrea Vacondio
- *
*/
class Listeners {
- private static final Logger LOG = LoggerFactory.getLogger(Listeners.class);
+ private static final Logger LOG = LoggerFactory.getLogger(Listeners.class);
- private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
- private Map<Class<?>, TreeSet<ListenerReferenceHolder>> listeners = new HashMap<>();
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private final Map<Class<?>, TreeSet<ListenerReferenceHolder>> listeners = new HashMap<>();
- <T> void add(Class<T> eventClass, Listener<T> listener, int priority, ReferenceStrength strength) {
- lock.writeLock().lock();
- try {
- TreeSet<ListenerReferenceHolder> set = nullSafeGetListenerHolders(eventClass);
- set.add(new ListenerReferenceHolder(priority, strength.getReference(new DefaultListenerWrapper(listener))));
- } finally {
- lock.writeLock().unlock();
- }
- }
+ <T> void add(Class<T> eventClass, Listener<T> listener, int priority, ReferenceStrength strength) {
+ lock.writeLock().lock();
+ try {
+ TreeSet<ListenerReferenceHolder> set = nullSafeGetListenerHolders(eventClass);
+ set.add(new ListenerReferenceHolder(priority, strength.getReference(new DefaultListenerWrapper(listener))));
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
- public Set<Class<?>> addAll(Object bean, List<ReflectiveListenerDescriptor> descriptors) {
- Set<Class<?>> updatedEventClasses = new HashSet<>();
- lock.writeLock().lock();
- try {
- for (ReflectiveListenerDescriptor current : descriptors) {
- Class<?> eventClass = current.getMethod().getParameterTypes()[0];
- TreeSet<ListenerReferenceHolder> set = nullSafeGetListenerHolders(eventClass);
- set.add(new ListenerReferenceHolder(current.getListenerAnnotation().priority(),
- current.getListenerAnnotation().strength()
- .getReference(new ReflectiveListenerWrapper(bean, current.getMethod()))));
- updatedEventClasses.add(eventClass);
- }
+ public Set<Class<?>> addAll(Object bean, List<ReflectiveListenerDescriptor> descriptors) {
+ Set<Class<?>> updatedEventClasses = new HashSet<>();
+ lock.writeLock().lock();
+ try {
+ for (ReflectiveListenerDescriptor current : descriptors) {
+ Class<?> eventClass = current.getMethod().getParameterTypes()[0];
+ TreeSet<ListenerReferenceHolder> set = nullSafeGetListenerHolders(eventClass);
+ set.add(new ListenerReferenceHolder(current.getListenerAnnotation().priority(),
+ current.getListenerAnnotation().strength()
+ .getReference(new ReflectiveListenerWrapper(bean, current.getMethod()))));
+ updatedEventClasses.add(eventClass);
+ }
- } finally {
- lock.writeLock().unlock();
- }
- return updatedEventClasses;
- }
+ } finally {
+ lock.writeLock().unlock();
+ }
+ return updatedEventClasses;
+ }
- private TreeSet<ListenerReferenceHolder> nullSafeGetListenerHolders(Class<?> eventClass) {
- TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
- if (set == null) {
- set = new TreeSet<>();
- listeners.put(eventClass, set);
- }
- return set;
- }
+ private TreeSet<ListenerReferenceHolder> nullSafeGetListenerHolders(Class<?> eventClass) {
+ return listeners.computeIfAbsent(eventClass, k -> new TreeSet<>());
+ }
- /**
- * Removes the listener if present. It also removes the listeners set from
- * the map if the set is empty.
- *
- * @param eventClass
- * @param listener
- * @return true if the listener was present and has been removed
- */
- <T> boolean remove(Class<T> eventClass, Listener<T> listener) {
- lock.readLock().lock();
- TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
- if (set != null) {
- lock.readLock().unlock();
- lock.writeLock().lock();
- try {
- DefaultListenerWrapper wrapper = new DefaultListenerWrapper(listener);
- for (ListenerReferenceHolder current : set) {
- if (wrapper.equals(current.getListenerWrapper())) {
- return removeListenerAndSetIfNeeded(eventClass, current, set);
- }
- }
- return false;
- } finally {
- lock.writeLock().unlock();
- }
- }
- lock.readLock().unlock();
- return false;
- }
+ /**
+ * Removes the listener listening for the given event if present. It also removes the listeners set from the map if the set is empty.
+ *
+ * @return true if the listener was present and has been removed
+ */
+ <T> boolean remove(Class<T> eventClass, Listener<T> listener) {
+ lock.readLock().lock();
+ TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
+ if (set != null) {
+ lock.readLock().unlock();
+ lock.writeLock().lock();
+ try {
+ DefaultListenerWrapper wrapper = new DefaultListenerWrapper(listener);
+ for (ListenerReferenceHolder current : set) {
+ if (wrapper.equals(current.getListenerWrapper())) {
+ return removeListenerAndSetIfNeeded(eventClass, current, set);
+ }
+ }
+ return false;
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+ lock.readLock().unlock();
+ return false;
+ }
- /**
- * Removes the listener if present. It also removes the listeners set from
- * the map if the set is empty.
- *
- * @param eventClass
- * @param listener
- * @return true if the listener was present and has been removed
- */
- boolean remove(Class<?> eventClass, ListenerReferenceHolder listener) {
- lock.readLock().lock();
- TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
- if (set != null) {
- lock.readLock().unlock();
- lock.writeLock().lock();
- try {
- return removeListenerAndSetIfNeeded(eventClass, listener, set);
- } finally {
- lock.writeLock().unlock();
- }
- }
- lock.readLock().unlock();
- return false;
- }
+ /**
+ * Removes the listener listening for the given event if present. It also removes the listeners set from the map if the set is empty.
+ *
+ * @return true if the listener was present and has been removed
+ */
+ boolean remove(Class<?> eventClass, ListenerReferenceHolder listener) {
+ lock.readLock().lock();
+ TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
+ if (set != null) {
+ lock.readLock().unlock();
+ lock.writeLock().lock();
+ try {
+ return removeListenerAndSetIfNeeded(eventClass, listener, set);
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+ lock.readLock().unlock();
+ return false;
+ }
- private boolean removeListenerAndSetIfNeeded(Class<?> eventClass, ListenerReferenceHolder listener,
- TreeSet<ListenerReferenceHolder> set) {
- if (set.remove(listener)) {
- if (set.isEmpty()) {
- listeners.remove(eventClass);
- LOG.trace("Removed empty listeners set for {}", eventClass);
- }
- return true;
- }
- return false;
- }
+ private boolean removeListenerAndSetIfNeeded(Class<?> eventClass, ListenerReferenceHolder listener,
+ TreeSet<ListenerReferenceHolder> set) {
+ if (set.remove(listener)) {
+ if (set.isEmpty()) {
+ listeners.remove(eventClass);
+ LOG.trace("Removed empty listeners set for {}", eventClass);
+ }
+ return true;
+ }
+ return false;
+ }
- /**
- * @param eventClass
- * @return A sorted set containing the listeners queue for the given class.
- */
- List<ListenerReferenceHolder> nullSafeGetListeners(Class<?> eventClass) {
- requireNotNull(eventClass);
- lock.readLock().lock();
- try {
- TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
- if (set == null) {
- return Collections.emptyList();
- }
- return new ArrayList<>(set);
- } finally {
- lock.readLock().unlock();
- }
- }
+ /**
+ * @return A sorted set containing the listeners queue for the given class.
+ */
+ List<ListenerReferenceHolder> nullSafeGetListeners(Class<?> eventClass) {
+ requireNotNull(eventClass);
+ lock.readLock().lock();
+ try {
+ TreeSet<ListenerReferenceHolder> set = listeners.get(eventClass);
+ if (set == null) {
+ return Collections.emptyList();
+ }
+ return new ArrayList<>(set);
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
- /**
- * Wraps a listener defined either explicitly or picked up by the annotation
- * processor
- *
- * @author Andrea Vacondio
- *
- */
- interface ListenerWrapper {
- void onEvent(Envelope event);
- }
+ /**
+ * Wraps a listener defined either explicitly or picked up by the annotation processor
+ *
+ * @author Andrea Vacondio
+ */
+ interface ListenerWrapper {
+ void onEvent(Envelope event);
+ }
- /**
- * Listener wrapper around an explicitly defined {@link Listener}
- *
- * @author Andrea Vacondio
- *
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static final class DefaultListenerWrapper implements ListenerWrapper {
- private Listener wrapped;
+ /**
+ * Listener wrapper around an explicitly defined {@link Listener}
+ *
+ * @author Andrea Vacondio
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private static final class DefaultListenerWrapper implements ListenerWrapper {
+ private final Listener wrapped;
- private DefaultListenerWrapper(Listener wrapped) {
- this.wrapped = wrapped;
- }
+ private DefaultListenerWrapper(Listener wrapped) {
+ this.wrapped = wrapped;
+ }
- public void onEvent(Envelope event) {
- wrapped.onEvent(event.getEvent());
- event.notified();
- }
+ public void onEvent(Envelope event) {
+ wrapped.onEvent(event.getEvent());
+ event.notified();
+ }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((wrapped == null) ? 0 : wrapped.hashCode());
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((wrapped == null) ? 0 : wrapped.hashCode());
+ return result;
+ }
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || !(o instanceof DefaultListenerWrapper)) {
- return false;
- }
- DefaultListenerWrapper other = (DefaultListenerWrapper) o;
- return wrapped.equals(other.wrapped);
- }
- }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof DefaultListenerWrapper)) {
+ return false;
+ }
+ DefaultListenerWrapper other = (DefaultListenerWrapper) o;
+ return wrapped.equals(other.wrapped);
+ }
+ }
- /**
- * Reflective invocation of an annotated listener
- *
- * @author Andrea Vacondio
- *
- */
- private static final class ReflectiveListenerWrapper implements ListenerWrapper {
- private Object bean;
- private Method method;
+ /**
+ * Reflective invocation of an annotated listener
+ *
+ * @author Andrea Vacondio
+ */
+ private static final class ReflectiveListenerWrapper implements ListenerWrapper {
+ private final Object bean;
+ private final Method method;
- public ReflectiveListenerWrapper(Object bean, Method method) {
- this.bean = bean;
- this.method = method;
- this.method.setAccessible(true);
- }
+ public ReflectiveListenerWrapper(Object bean, Method method) {
+ this.bean = bean;
+ this.method = method;
+ this.method.setAccessible(true);
+ }
- public void onEvent(Envelope event) {
- try {
- method.invoke(bean, event.getEvent());
- } catch (IllegalAccessException e) {
- throw new EventStudioException("Exception invoking reflective method", e);
- } catch (InvocationTargetException e) {
- if (e.getCause() instanceof BroadcastInterruptionException) {
- throw (BroadcastInterruptionException) e.getCause();
- }
- throw new EventStudioException("Reflective method invocation exception", e);
- }
- event.notified();
- }
- }
+ public void onEvent(Envelope event) {
+ try {
+ method.invoke(bean, event.getEvent());
+ } catch (IllegalAccessException e) {
+ throw new EventStudioException("Exception invoking reflective method", e);
+ } catch (InvocationTargetException e) {
+ if (e.getCause() instanceof BroadcastInterruptionException) {
+ throw (BroadcastInterruptionException) e.getCause();
+ }
+ throw new EventStudioException("Reflective method invocation exception", e);
+ }
+ event.notified();
+ }
+ }
- /**
- * Holder for a {@link ListenerWrapper}
- *
- * @author Andrea Vacondio
- *
- */
- static class ListenerReferenceHolder implements Comparable<ListenerReferenceHolder> {
- int priority = 0;
- private Entity<? extends ListenerWrapper> reference;
+ /**
+ * Holder for a {@link ListenerWrapper}
+ *
+ * @author Andrea Vacondio
+ */
+ static class ListenerReferenceHolder implements Comparable<ListenerReferenceHolder> {
+ int priority = 0;
+ private final Entity<? extends ListenerWrapper> reference;
- public ListenerReferenceHolder(int priority, Entity<? extends ListenerWrapper> reference) {
- requireNotNull(reference);
- this.priority = priority;
- this.reference = reference;
- }
+ public ListenerReferenceHolder(int priority, Entity<? extends ListenerWrapper> reference) {
+ requireNotNull(reference);
+ this.priority = priority;
+ this.reference = reference;
+ }
- public int compareTo(ListenerReferenceHolder o) {
- if (this.priority < o.priority) {
- return -1;
- }
- if (this.priority > o.priority) {
- return 1;
- }
- // same priority
- int retVal = this.hashCode() - o.hashCode();
- // same hashcode but not equals. This shouldn't happen but according
- // to hascode documentation is not required and since we don't want
- // ListenerReferenceHolder to
- // disappear from the TreeSet we return an arbitrary integer != from
- // 0
- if (retVal == 0 && !this.equals(o)) {
- retVal = -1;
- }
- return retVal;
- }
+ public int compareTo(ListenerReferenceHolder o) {
+ if (this.priority < o.priority) {
+ return -1;
+ }
+ if (this.priority > o.priority) {
+ return 1;
+ }
+ // same priority
+ int retVal = this.hashCode() - o.hashCode();
+ // same hashcode but not equals. This shouldn't happen but according
+ // to hascode documentation is not required and since we don't want
+ // ListenerReferenceHolder to
+ // disappear from the TreeSet we return an arbitrary integer != from
+ // 0
+ if (retVal == 0 && !this.equals(o)) {
+ retVal = -1;
+ }
+ return retVal;
+ }
- public ListenerWrapper getListenerWrapper() {
- return reference.get();
- }
- }
+ public ListenerWrapper getListenerWrapper() {
+ return reference.get();
+ }
+ }
}
=====================================
src/main/java/org/pdfsam/eventstudio/ReferenceStrength.java
=====================================
@@ -47,8 +47,6 @@ public enum ReferenceStrength {
};
/**
- *
- * @param referent
* @return the referent wrapped with the appropriate {@link Entity} instance.
*/
abstract <T> Entity<T> getReference(T referent);
=====================================
src/main/java/org/pdfsam/eventstudio/Station.java
=====================================
@@ -47,8 +47,8 @@ class Station {
private static final Logger LOG = LoggerFactory.getLogger(Station.class);
- private ConcurrentMap<Class<?>, BlockingQueue<Object>> queues = new ConcurrentHashMap<>();
- private Listeners listeners = new Listeners();
+ private final ConcurrentMap<Class<?>, BlockingQueue<Object>> queues = new ConcurrentHashMap<>();
+ private final Listeners listeners = new Listeners();
private volatile Supervisor supervisor = Supervisor.SLACKER;
private final String name;
=====================================
src/main/java/org/pdfsam/eventstudio/Stations.java
=====================================
@@ -36,10 +36,9 @@ class Stations {
private static final Logger LOG = LoggerFactory.getLogger(Stations.class);
- private ConcurrentMap<String, Station> stations = new ConcurrentHashMap<>();
+ private final ConcurrentMap<String, Station> stations = new ConcurrentHashMap<>();
/**
- * @param stationName
* @return the station with the given name. It safely creates a new {@link Station} if a station with the given name does not exist.
* @throws IllegalArgumentException
* if the station name is blank or null
=====================================
src/main/java/org/pdfsam/eventstudio/Supervisor.java
=====================================
@@ -42,8 +42,6 @@ public interface Supervisor {
/**
* Inspect the event
- *
- * @param event
*/
void inspect(Object event);
=====================================
src/main/java/org/pdfsam/eventstudio/util/ReflectionUtils.java
=====================================
@@ -35,8 +35,6 @@ public final class ReflectionUtils {
/**
* Given a concrete class and a method name, it tries to infer the Class of the first parameter of the method
*
- * @param clazz
- * @param methodName
* @return the class or null if nothing found
*/
@SuppressWarnings("rawtypes")
=====================================
src/main/java/org/pdfsam/eventstudio/util/RequireUtils.java
=====================================
@@ -32,7 +32,7 @@ public final class RequireUtils {
/**
* Requires that the input string is not blank
*
- * @param victim
+ * @param victim the string to be tested
* @throws IllegalArgumentException
* if the input is blank
*/
@@ -45,7 +45,7 @@ public final class RequireUtils {
/**
* Requires that the input argument is not null
*
- * @param victim
+ * @param victim the string to be tested
* @throws IllegalArgumentException
* if the input is null
*/
=====================================
src/main/java/org/pdfsam/eventstudio/util/StringUtils.java
=====================================
@@ -38,8 +38,6 @@ public final class StringUtils {
}
/**
- * @param input
- * @param defaultValue
* @return the unchanged input if it's not blank, the default value otherwise
*/
public static String defaultString(String input, String defaultValue) {
=====================================
src/test/java/org/pdfsam/eventstudio/AnnotationsTest.java
=====================================
@@ -18,6 +18,7 @@
package org.pdfsam.eventstudio;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@@ -99,7 +100,7 @@ public class AnnotationsTest {
public void overriddenNotAnnotatedListeners() throws IllegalAccessException, InvocationTargetException {
ReflectiveMetadata metadata = Annotations.process(new ChildListener());
List<ReflectiveListenerDescriptor> hiddenStation = metadata.getDescriptors().get("");
- assertEquals(null, hiddenStation);
+ assertNull(hiddenStation);
}
@Test
@@ -197,7 +198,7 @@ public class AnnotationsTest {
public enum WhateverEnum {
CHUCK,
- NORRIS;
+ NORRIS
}
public static class StationFieldEnum {
=====================================
src/test/java/org/pdfsam/eventstudio/util/ReflectionUtilsTest.java
=====================================
@@ -18,6 +18,7 @@
package org.pdfsam.eventstudio.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.pdfsam.eventstudio.Listener;
@@ -36,7 +37,7 @@ public class ReflectionUtilsTest {
@Test
public void testFailingInfer() {
SecondTestListener<TestEvent> victim = new SecondTestListener<>();
- assertEquals(null, ReflectionUtils.inferParameterClass(victim.getClass(), "onEvent"));
+ assertNull(ReflectionUtils.inferParameterClass(victim.getClass(), "onEvent"));
}
private class TestListener implements Listener<TestEvent> {
View it on GitLab: https://salsa.debian.org/java-team/libsejda-eventstudio-java/-/commit/733f26ad19a9841cbd7e7e96e9bba0e4425ca3b0
--
View it on GitLab: https://salsa.debian.org/java-team/libsejda-eventstudio-java/-/commit/733f26ad19a9841cbd7e7e96e9bba0e4425ca3b0
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220211/07fb9f9a/attachment.htm>
More information about the pkg-java-commits
mailing list