Skip to content

Commit

Permalink
SAK-44338 Event: Time => Instant (sakaiproject#8605)
Browse files Browse the repository at this point in the history
  • Loading branch information
axxter99 authored Oct 2, 2020
1 parent 2011a77 commit 6edf76c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,8 @@ public List<String> findDelayIds(String resource)
return ids;
}

/* (non-Javadoc)
* @see org.sakaiproject.content.providers.EventDelayHandler#createDelay(org.sakaiproject.event.api.Event)
*/
public String createDelay(Event event, Time fireTime)
{
return createDelay(event, event.getUserId(), fireTime);
}

/* (non-Javadoc)
* @see org.sakaiproject.content.providers.EventDelayHandler#createDelay(org.sakaiproject.event.api.Event, java.lang.String)
*/
@SuppressWarnings("unchecked")
public String createDelay(Event event, String userId, Time fireTime)
{
@Override
public String createDelay(Event event, String userId, Instant fireTime) {
// delete previous like delays
deleteDelay(event);

Expand All @@ -236,11 +224,17 @@ public String createDelay(Event event, String userId, Time fireTime)

// Schedule the new delayed invocation
log.info("Creating new delayed event [" + id + "]");
Instant fireInstant = Instant.ofEpochMilli(fireTime.getTime());
schedInvocMgr.createDelayedInvocation(fireInstant, BaseEventDelayHandler.class.getName(), id);
schedInvocMgr.createDelayedInvocation(fireTime, BaseEventDelayHandler.class.getName(), id);
return id;
}


@Override
public String createDelay(Event event, Instant fireTime) {
return createDelay(event, event.getUserId(), fireTime);
}


/* (non-Javadoc)
* @see org.sakaiproject.content.providers.EventDelayHandler#deleteDelayById(java.lang.String)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

package org.sakaiproject.event.api;

import java.time.Instant;
import java.util.List;

import org.sakaiproject.time.api.Time;

/**
* Event delayers delay an event for future propagation by the system.
Expand Down Expand Up @@ -78,7 +78,7 @@ public interface EventDelayHandler
* @param event
* @return The ID of the delay
*/
String createDelay(Event event, Time fireTime);
String createDelay(Event event, Instant fireTime);

/**
* Schedules a delayed invocation of this notification to run at the requested time.
Expand All @@ -87,7 +87,7 @@ public interface EventDelayHandler
* @param userId
* @return The ID of the delay
*/
String createDelay(Event event, String userId, Time fireTime);
String createDelay(Event event, String userId, Instant fireTime);

/**
* Delete an event delay by referencing the delay ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

package org.sakaiproject.event.api;

import java.time.Instant;
import java.util.Observer;

import org.sakaiproject.event.api.LearningResourceStoreService.LRS_Statement;
import org.sakaiproject.time.api.Time;
import org.sakaiproject.user.api.User;

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public interface EventTrackingService
* @param event
* @param fireTime
*/
void delay(Event event, Time fireTime);
void delay(Event event, Instant fireTime);

/**
* Cancel all delayed events for a resource that haven't yet fired.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
package org.sakaiproject.event.cover;

import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.time.api.Time;

/**
* <p>
Expand Down Expand Up @@ -133,13 +131,7 @@ public static void post(org.sakaiproject.event.api.Event param0)
service.post(param0);
}

public static void delay(Event event, Time fireTime)
{
org.sakaiproject.event.api.EventTrackingService service = getInstance();
if (service == null) return;

service.delay(event, fireTime);
}

public static void cancelDelays(String resource)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2975,17 +2975,17 @@ private void postAvailableEvent(GroupAwareEntity entity, String ref, int priorit
if ( ! entity.isAvailable() )
{
// schedule an event to tell when resource becomes available
if (entity.getReleaseDate() != null)
if (entity.getReleaseInstant() != null)
{
eventTrackingService.delay(eventTrackingService.newEvent(EVENT_RESOURCE_AVAILABLE, ref,
false, priority), entity.getReleaseDate());
false, priority), entity.getReleaseInstant());
entity.getProperties().addProperty(PROP_AVAIL_NOTI, Boolean.FALSE.toString());
}
// schedule an event to tell when resource becomes unavailable
if ( entity.getRetractDate() != null )
if ( entity.getRetractInstant() != null )
{
eventTrackingService.delay(eventTrackingService.newEvent(EVENT_RESOURCE_UNAVAILABLE, ref,
false, priority), entity.getRetractDate());
false, priority), entity.getRetractInstant());
entity.getProperties().addProperty(PROP_AVAIL_NOTI, Boolean.FALSE.toString());
}
}
Expand All @@ -3005,10 +3005,10 @@ private void postAvailableEvent(GroupAwareEntity entity, String ref, int priorit
}

// schedule an event to tell when resource becomes unavailable
if ( entity.getRetractDate() != null )
if ( entity.getRetractInstant() != null )
{
eventTrackingService.delay(eventTrackingService.newEvent(EVENT_RESOURCE_UNAVAILABLE, ref,
false, priority), entity.getRetractDate());
false, priority), entity.getRetractInstant());
entity.getProperties().addProperty(PROP_AVAIL_NOTI, Boolean.FALSE.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.sakaiproject.event.impl;

import java.time.Instant;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
Expand Down Expand Up @@ -342,10 +343,11 @@ public void post(Event event, User user)
securityService().popAdvisor();
}

public void delay(Event event, Time fireTime)
@Override
public void delay(Event event, Instant fireTime)
{
Time now = timeService().newTime();
if (fireTime == null || fireTime.before(now))
Instant now = Instant.now();
if (fireTime == null || fireTime.isBefore(now))
{
postEvent(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package org.sakai.memory.impl.test;

import java.time.Instant;
import java.util.Observer;

import org.sakaiproject.event.api.Event;
Expand Down Expand Up @@ -166,4 +167,10 @@ public void delay(Event event, Time fireTime)
// TODO Auto-generated method stub

}

@Override
public void delay(Event event, Instant fireTime) {
// TODO Auto-generated method stub

}
}

0 comments on commit 6edf76c

Please sign in to comment.