-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from diging/develop
prepare release
- Loading branch information
Showing
14 changed files
with
379 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...n/java/edu/asu/diging/gilesecosystem/web/controllers/admin/CurrentRequestsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package edu.asu.diging.gilesecosystem.web.controllers.admin; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.bouncycastle.asn1.cms.TimeStampedDataParser; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService; | ||
import edu.asu.diging.gilesecosystem.web.service.impl.TimestampedRequestData; | ||
|
||
@Controller | ||
public class CurrentRequestsController { | ||
|
||
@Autowired | ||
private IProcessingRequestService requestService; | ||
|
||
@RequestMapping("admin/requests/current") | ||
public String showCurrentRequests() { | ||
return "admin/requests/current"; | ||
} | ||
|
||
@RequestMapping("admin/requests/current/processed") | ||
public ResponseEntity<List<TimestampedRequestData>> getCurrentProcessedRequests() { | ||
List<TimestampedRequestData> requests = requestService.getCurrentReceivedRequests(); | ||
Collections.reverse(requests); | ||
return new ResponseEntity<List<TimestampedRequestData>>(requests, HttpStatus.OK); | ||
} | ||
|
||
@RequestMapping("admin/requests/current/sent") | ||
public ResponseEntity<List<TimestampedRequestData>> getCurrentSentRequests() { | ||
List<TimestampedRequestData> requests = requestService.getCurrentSentRequests(); | ||
Collections.reverse(requests); | ||
return new ResponseEntity<List<TimestampedRequestData>>(requests, HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...co/src/main/java/edu/asu/diging/gilesecosystem/web/service/IProcessingRequestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package edu.asu.diging.gilesecosystem.web.service; | ||
|
||
import java.util.List; | ||
|
||
import edu.asu.diging.gilesecosystem.requests.IRequest; | ||
import edu.asu.diging.gilesecosystem.web.service.impl.TimestampedRequestData; | ||
|
||
/** | ||
* Service that holds recent processing requests (sent and received). | ||
* | ||
* @author jdamerow | ||
* | ||
*/ | ||
public interface IProcessingRequestService { | ||
|
||
/** | ||
* Method to append new requests. If there are more than the maximum number of | ||
* current requests in the queue (as specified in the config file), the first one | ||
* is removed from the queue before adding the new one. | ||
* | ||
* This method does not have to be thread-safe as it is ok if there are a few too | ||
* many or too few elements in the queue. | ||
* | ||
* @param request Request to be added to current queue. | ||
*/ | ||
void addReceivedRequest(IRequest request); | ||
|
||
/** | ||
* Returns recently received requests as a list. | ||
* | ||
* @return List of recently received requests with the oldest request first. | ||
*/ | ||
List<TimestampedRequestData> getCurrentReceivedRequests(); | ||
|
||
/** | ||
* Returns recently sent requests as a list. | ||
* | ||
* @return List of recently sent requests with the oldest request first. | ||
*/ | ||
List<TimestampedRequestData> getCurrentSentRequests(); | ||
|
||
/** | ||
* Method to add a new request to the sent queue. If there are more than the maximum number of | ||
* current requests in the queue (as specified in the config file), the first one | ||
* is removed from the queue before adding the new one. | ||
* | ||
* @param request Sent request to be added to the queue. | ||
*/ | ||
void addSentRequest(IRequest request); | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...rc/main/java/edu/asu/diging/gilesecosystem/web/service/impl/ProcessingRequestService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package edu.asu.diging.gilesecosystem.web.service.impl; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Queue; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import edu.asu.diging.gilesecosystem.requests.IRequest; | ||
import edu.asu.diging.gilesecosystem.util.properties.IPropertiesManager; | ||
import edu.asu.diging.gilesecosystem.web.service.IProcessingRequestService; | ||
import edu.asu.diging.gilesecosystem.web.service.properties.Properties; | ||
|
||
/** | ||
* Not thread-safe implementation of {@link IProcessingRequestService} using a {@link Queue}. | ||
* | ||
* The number of maximum requests in the queue can be defined using the | ||
* property: current_requests_max_number. | ||
* | ||
* @author jdamerow | ||
* | ||
*/ | ||
@Service | ||
public class ProcessingRequestService implements IProcessingRequestService { | ||
|
||
@Autowired | ||
private IPropertiesManager propertyManager; | ||
|
||
private Queue<TimestampedRequestData> currentReceivedRequests; | ||
|
||
private Queue<TimestampedRequestData> currentSentRequests; | ||
|
||
@PostConstruct | ||
public void init() { | ||
currentReceivedRequests = new ConcurrentLinkedQueue<>(); | ||
currentSentRequests = new ConcurrentLinkedQueue<>(); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.gilesecosystem.web.service.impl.IProcessingRequestService#addReceivedRequest(edu.asu.diging.gilesecosystem.requests.IRequest) | ||
*/ | ||
@Override | ||
public void addReceivedRequest(IRequest request) { | ||
if (currentReceivedRequests.size() > new Integer(propertyManager.getProperty(Properties.CURRENT_REQUESTS_MAX))) { | ||
currentReceivedRequests.poll(); | ||
} | ||
currentReceivedRequests.add(new TimestampedRequestData(request, ZonedDateTime.now())); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see edu.asu.diging.gilesecosystem.web.service.impl.IProcessingRequestService#getCurrentReceivedRequests() | ||
*/ | ||
@Override | ||
public List<TimestampedRequestData> getCurrentReceivedRequests() { | ||
return new ArrayList<>(currentReceivedRequests); | ||
} | ||
|
||
@Override | ||
public void addSentRequest(IRequest request) { | ||
if (currentSentRequests.size() > new Integer(propertyManager.getProperty(Properties.CURRENT_REQUESTS_MAX))) { | ||
currentSentRequests.poll(); | ||
} | ||
currentSentRequests.add(new TimestampedRequestData(request, ZonedDateTime.now())); | ||
} | ||
|
||
@Override | ||
public List<TimestampedRequestData> getCurrentSentRequests() { | ||
return new ArrayList<>(currentSentRequests); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../src/main/java/edu/asu/diging/gilesecosystem/web/service/impl/TimestampedRequestData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package edu.asu.diging.gilesecosystem.web.service.impl; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import edu.asu.diging.gilesecosystem.requests.IRequest; | ||
|
||
public class TimestampedRequestData { | ||
public IRequest request; | ||
public ZonedDateTime time; | ||
|
||
public TimestampedRequestData(IRequest request, ZonedDateTime time) { | ||
this.request = request; | ||
this.time = time; | ||
} | ||
|
||
public IRequest getRequest() { | ||
return request; | ||
} | ||
public void setRequest(IRequest request) { | ||
this.request = request; | ||
} | ||
public ZonedDateTime getTime() { | ||
return time; | ||
} | ||
public void setTime(ZonedDateTime time) { | ||
this.time = time; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.