Merge pull request #2429 from mposolda/master
KEYCLOAK-2713 Fix error at startup
This commit is contained in:
commit
7bdf9f4ba1
10 changed files with 26 additions and 14 deletions
|
@ -40,7 +40,6 @@ import org.keycloak.connections.jpa.util.JpaUtils;
|
|||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.provider.ServerInfoAwareProviderFactory;
|
||||
import org.keycloak.services.scheduled.ScheduledTaskRunner;
|
||||
import org.keycloak.timer.TimerProvider;
|
||||
|
||||
/**
|
||||
|
@ -274,7 +273,7 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
|
|||
protected void startGlobalStats(KeycloakSession session, int globalStatsIntervalSecs) {
|
||||
logger.debugf("Started Hibernate statistics with the interval %s seconds", globalStatsIntervalSecs);
|
||||
TimerProvider timer = session.getProvider(TimerProvider.class);
|
||||
timer.schedule(new ScheduledTaskRunner(session.getKeycloakSessionFactory(), new HibernateStatsReporter(emf)), globalStatsIntervalSecs * 1000, "ReportHibernateGlobalStats");
|
||||
timer.scheduleTask(new HibernateStatsReporter(emf), globalStatsIntervalSecs * 1000, "ReportHibernateGlobalStats");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.hibernate.stat.QueryStatistics;
|
|||
import org.hibernate.stat.Statistics;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.services.scheduled.ScheduledTask;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.services.scheduled;
|
||||
package org.keycloak.timer;
|
||||
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
|
|
@ -24,7 +24,9 @@ import org.keycloak.provider.Provider;
|
|||
*/
|
||||
public interface TimerProvider extends Provider {
|
||||
|
||||
public void schedule(Runnable runnable, long interval, String taskName);
|
||||
public void schedule(Runnable runnable, long intervalMillis, String taskName);
|
||||
|
||||
public void scheduleTask(ScheduledTask scheduledTask, long intervalMillis, String taskName);
|
||||
|
||||
public void cancelTask(String taskName);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.keycloak.services.scheduled;
|
|||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.keycloak.services.scheduled;
|
|||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserSessionProvider;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.keycloak.cluster.ClusterProvider;
|
|||
import org.keycloak.cluster.ExecutionResult;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
|
||||
/**
|
||||
* Ensures that there are not concurrent executions of same task (either on this host or any other cluster host)
|
||||
|
|
|
@ -17,13 +17,10 @@
|
|||
|
||||
package org.keycloak.services.scheduled;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.keycloak.cluster.ClusterProvider;
|
||||
import org.keycloak.cluster.ExecutionResult;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.KeycloakSessionFactory;
|
||||
import org.keycloak.services.ServicesLogger;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
package org.keycloak.timer.basic;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.services.scheduled.ScheduledTaskRunner;
|
||||
import org.keycloak.timer.ScheduledTask;
|
||||
import org.keycloak.timer.TimerProvider;
|
||||
|
||||
import java.util.Timer;
|
||||
|
@ -30,16 +33,18 @@ public class BasicTimerProvider implements TimerProvider {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(BasicTimerProvider.class);
|
||||
|
||||
private final KeycloakSession session;
|
||||
private final Timer timer;
|
||||
private final BasicTimerProviderFactory factory;
|
||||
|
||||
public BasicTimerProvider(Timer timer, BasicTimerProviderFactory factory) {
|
||||
public BasicTimerProvider(KeycloakSession session, Timer timer, BasicTimerProviderFactory factory) {
|
||||
this.session = session;
|
||||
this.timer = timer;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void schedule(final Runnable runnable, final long interval, String taskName) {
|
||||
public void schedule(final Runnable runnable, final long intervalMillis, String taskName) {
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -53,8 +58,14 @@ public class BasicTimerProvider implements TimerProvider {
|
|||
existingTask.cancel();
|
||||
}
|
||||
|
||||
logger.debugf("Starting task '%s' with interval '%d'", taskName, interval);
|
||||
timer.schedule(task, interval, interval);
|
||||
logger.debugf("Starting task '%s' with interval '%d'", taskName, intervalMillis);
|
||||
timer.schedule(task, intervalMillis, intervalMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleTask(ScheduledTask scheduledTask, long intervalMillis, String taskName) {
|
||||
ScheduledTaskRunner scheduledTaskRunner = new ScheduledTaskRunner(session.getKeycloakSessionFactory(), scheduledTask);
|
||||
this.schedule(scheduledTaskRunner, intervalMillis, taskName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BasicTimerProviderFactory implements TimerProviderFactory {
|
|||
|
||||
@Override
|
||||
public TimerProvider create(KeycloakSession session) {
|
||||
return new BasicTimerProvider(timer, this);
|
||||
return new BasicTimerProvider(session, timer, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue