Loading pom.xml +13 −0 Changes for pom.xml: 13 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ <camel.version>4.0.0-RC1</camel.version> <slf4j-api.version>1.7.5</slf4j-api.version> <slf4j-simple.version>1.7.28</slf4j-simple.version> <mysql-connector.version>${mysql.connector.version}</mysql-connector.version> </properties> <repositories> Loading Loading @@ -162,6 +163,18 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.etsi.osl</groupId> <artifactId>org.etsi.osl.model.tmf</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> <version>${mysql-connector.version}</version> </dependency> <!-- Testing --> Loading src/main/java/org/etsi/osl/metrico/LocalMysqlDialect.java 0 → 100644 +29 −0 Changes for src/main/java/org/etsi/osl/metrico/LocalMysqlDialect.java: 29 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2019 openslice.io * %% * 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. * =========================LICENSE_END================================== */ package org.etsi.osl.metrico; import org.hibernate.dialect.MySQLDialect; ; public class LocalMysqlDialect extends MySQLDialect { @Override public String getTableTypeString() { return " DEFAULT CHARSET=utf8"; } } src/main/java/org/etsi/osl/metrico/model/Job.java +30 −0 Changes for src/main/java/org/etsi/osl/metrico/model/Job.java: 30 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -40,6 +40,22 @@ public class Job { private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private static final Map<UUID, Job> jobs = new ConcurrentHashMap<>(); /** * Schedules a new job to be executed periodically. * <p> * This method creates a new job with a unique identifier, schedules it to run at a fixed rate * with the specified initial delay and periodic delay. The job's execution state is initially set * to {@link ExecutionStateType#PENDING}. If the job is successfully scheduled, its state changes to * {@link ExecutionStateType#INPROGRESS}. If the job cannot be scheduled due to a * {@link RejectedExecutionException}, its state is set to {@link ExecutionStateType#FAILED}. * </p> * * @param task the task to be executed by the job * @param initialDelay the time to delay first execution, in seconds * @param periodicDelay the period between successive executions, in seconds * @return the scheduled job with its unique identifier and state * @throws RejectedExecutionException if the task cannot be scheduled for execution */ public Job startJob(Runnable task, long initialDelay, long periodicDelay) { UUID jobId = UUID.randomUUID(); Job job = new Job(task); Loading @@ -58,6 +74,20 @@ public class Job { return job; } /** * Attempts to stop a job identified by its UUID. * <p> * This method checks if the job exists and its current state. If the job is already in a * {@link ExecutionStateType#CANCELLED} or {@link ExecutionStateType#COMPLETED} state, it logs * the status and returns. Otherwise, it attempts to cancel the job's future execution. * If the cancellation is successful, the job's state is set to {@link ExecutionStateType#CANCELLED}, * and it logs the successful stop. If the job cannot be stopped (e.g., already completed or cancelled), * its state is set to {@link ExecutionStateType#PENDING}, and a warning is logged. If the job does not * exist, it logs a warning. * </p> * * @param jobId the UUID of the job to stop */ public void stopJob(UUID jobId) { Job job = jobs.get(jobId); if (job != null) { Loading src/main/resources/application.yml +23 −1 Changes for src/main/resources/application.yml: 23 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,9 +3,31 @@ spring: activate: on-profile: "default" application: name: metco name: metrico main: web-application-type: servlet datasource: url: jdbc:mysql://localhost:13306/ostmfdb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC password: letmein username: root hikari: minimumIdle: 2 maximumPoolSize: 40 idleTimeout: 120000 connectionTimeout: 400000 leakDetectionThreshold: 100000 jpa: database-platform: org.etsi.osl.metrico.LocalMysqlDialect hibernate: ddl-auto: update show-sql: false generate-ddl: true properties: hibernate: connection: characterEncoding: utf-8 CharSet: utf-8 useUnicode: true # activemq: # brokerUrl: tcp://localhost:61616?jms.watchTopicAdvisories=false # user: artemis Loading Loading
pom.xml +13 −0 Changes for pom.xml: 13 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ <camel.version>4.0.0-RC1</camel.version> <slf4j-api.version>1.7.5</slf4j-api.version> <slf4j-simple.version>1.7.28</slf4j-simple.version> <mysql-connector.version>${mysql.connector.version}</mysql-connector.version> </properties> <repositories> Loading Loading @@ -162,6 +163,18 @@ <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> <dependency> <groupId>org.etsi.osl</groupId> <artifactId>org.etsi.osl.model.tmf</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> <version>${mysql-connector.version}</version> </dependency> <!-- Testing --> Loading
src/main/java/org/etsi/osl/metrico/LocalMysqlDialect.java 0 → 100644 +29 −0 Changes for src/main/java/org/etsi/osl/metrico/LocalMysqlDialect.java: 29 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2019 openslice.io * %% * 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. * =========================LICENSE_END================================== */ package org.etsi.osl.metrico; import org.hibernate.dialect.MySQLDialect; ; public class LocalMysqlDialect extends MySQLDialect { @Override public String getTableTypeString() { return " DEFAULT CHARSET=utf8"; } }
src/main/java/org/etsi/osl/metrico/model/Job.java +30 −0 Changes for src/main/java/org/etsi/osl/metrico/model/Job.java: 30 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -40,6 +40,22 @@ public class Job { private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private static final Map<UUID, Job> jobs = new ConcurrentHashMap<>(); /** * Schedules a new job to be executed periodically. * <p> * This method creates a new job with a unique identifier, schedules it to run at a fixed rate * with the specified initial delay and periodic delay. The job's execution state is initially set * to {@link ExecutionStateType#PENDING}. If the job is successfully scheduled, its state changes to * {@link ExecutionStateType#INPROGRESS}. If the job cannot be scheduled due to a * {@link RejectedExecutionException}, its state is set to {@link ExecutionStateType#FAILED}. * </p> * * @param task the task to be executed by the job * @param initialDelay the time to delay first execution, in seconds * @param periodicDelay the period between successive executions, in seconds * @return the scheduled job with its unique identifier and state * @throws RejectedExecutionException if the task cannot be scheduled for execution */ public Job startJob(Runnable task, long initialDelay, long periodicDelay) { UUID jobId = UUID.randomUUID(); Job job = new Job(task); Loading @@ -58,6 +74,20 @@ public class Job { return job; } /** * Attempts to stop a job identified by its UUID. * <p> * This method checks if the job exists and its current state. If the job is already in a * {@link ExecutionStateType#CANCELLED} or {@link ExecutionStateType#COMPLETED} state, it logs * the status and returns. Otherwise, it attempts to cancel the job's future execution. * If the cancellation is successful, the job's state is set to {@link ExecutionStateType#CANCELLED}, * and it logs the successful stop. If the job cannot be stopped (e.g., already completed or cancelled), * its state is set to {@link ExecutionStateType#PENDING}, and a warning is logged. If the job does not * exist, it logs a warning. * </p> * * @param jobId the UUID of the job to stop */ public void stopJob(UUID jobId) { Job job = jobs.get(jobId); if (job != null) { Loading
src/main/resources/application.yml +23 −1 Changes for src/main/resources/application.yml: 23 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,9 +3,31 @@ spring: activate: on-profile: "default" application: name: metco name: metrico main: web-application-type: servlet datasource: url: jdbc:mysql://localhost:13306/ostmfdb?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC password: letmein username: root hikari: minimumIdle: 2 maximumPoolSize: 40 idleTimeout: 120000 connectionTimeout: 400000 leakDetectionThreshold: 100000 jpa: database-platform: org.etsi.osl.metrico.LocalMysqlDialect hibernate: ddl-auto: update show-sql: false generate-ddl: true properties: hibernate: connection: characterEncoding: utf-8 CharSet: utf-8 useUnicode: true # activemq: # brokerUrl: tcp://localhost:61616?jms.watchTopicAdvisories=false # user: artemis Loading