forked from griddynamics/nexus-replication-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTful webservice to receive notifications of artifact uploads.
griddynamics#3 ArtifactUpdateApiClient#offerRequest now does not work in blocking way. Request is being added to internal queue. Background thread iterates through this queue, and submit Runnables to Executor.
- Loading branch information
1 parent
601963c
commit 7752e1f
Showing
8 changed files
with
235 additions
and
18 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
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
46 changes: 46 additions & 0 deletions
46
src/main/java/com/griddynamics/cd/nrp/internal/model/internal/ArtifactMetaInfoQueueDump.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,46 @@ | ||
/* | ||
* Copyright 2015, Grid Dynamics International, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package com.griddynamics.cd.nrp.internal.model.internal; | ||
|
||
import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; | ||
|
||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlElementWrapper; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* DTO Class encapsulates artifact replication queue | ||
*/ | ||
@XmlRootElement(name = "artifactMetaInfoBlockingQueueDump") | ||
public class ArtifactMetaInfoQueueDump { | ||
@XmlElement(name = "artifactMetaInfo") | ||
@XmlElementWrapper(name = "artifactMetaInfos") | ||
private final Set<ArtifactMetaInfo> artifactMetaInfos = new HashSet<>(); | ||
|
||
public void addArtifactMetaInfo(ArtifactMetaInfo artifactMetaInfo) { | ||
artifactMetaInfos.add(artifactMetaInfo); | ||
} | ||
public void addAllArtifactMetaInfo(Set<ArtifactMetaInfo> artifactMetaInfo) { | ||
artifactMetaInfos.addAll(artifactMetaInfo); | ||
} | ||
|
||
public Set<ArtifactMetaInfo> getArtifactMetaInfos() { | ||
return artifactMetaInfos; | ||
} | ||
|
||
} |
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
79 changes: 79 additions & 0 deletions
79
src/main/java/com/griddynamics/cd/nrp/internal/uploading/impl/FileBlockingQueue.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,79 @@ | ||
package com.griddynamics.cd.nrp.internal.uploading.impl; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.griddynamics.cd.nrp.internal.model.api.ArtifactMetaInfo; | ||
import com.griddynamics.cd.nrp.internal.model.internal.ArtifactMetaInfoQueueDump; | ||
import org.apache.commons.io.FileUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.Marshaller; | ||
import java.io.File; | ||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class FileBlockingQueue { | ||
|
||
private final BlockingQueue<ArtifactMetaInfo> internalBlockingQueue; | ||
private final String blockingQueueDumpFileName; | ||
|
||
private Logger log = LoggerFactory.getLogger(FileBlockingQueue.class); | ||
|
||
public FileBlockingQueue(BlockingQueue<ArtifactMetaInfo> blockingQueue, String blockingQueueDumpFileName) { | ||
this.internalBlockingQueue = blockingQueue; | ||
this.blockingQueueDumpFileName = blockingQueueDumpFileName; | ||
} | ||
|
||
public boolean offer(ArtifactMetaInfo e, long timeout, TimeUnit timeUnit) throws InterruptedException { | ||
synchronized (internalBlockingQueue) { | ||
boolean retVal = internalBlockingQueue.offer(e, timeout, timeUnit); | ||
saveQueueToFile(); | ||
internalBlockingQueue.notify(); | ||
return retVal; | ||
} | ||
} | ||
|
||
public ArtifactMetaInfo peek() throws InterruptedException { | ||
synchronized (internalBlockingQueue) { | ||
while (internalBlockingQueue.isEmpty()) { | ||
internalBlockingQueue.wait(); | ||
} | ||
return internalBlockingQueue.peek(); | ||
} | ||
} | ||
|
||
public ArtifactMetaInfo take() throws InterruptedException { | ||
synchronized (internalBlockingQueue) { | ||
while (internalBlockingQueue.isEmpty()) { | ||
internalBlockingQueue.wait(); | ||
} | ||
ArtifactMetaInfo retVal = internalBlockingQueue.take(); | ||
saveQueueToFile(); | ||
return retVal; | ||
|
||
} | ||
} | ||
|
||
private synchronized void saveQueueToFile() { | ||
|
||
try { | ||
String backupBlockingQueueDumpFileName = blockingQueueDumpFileName + ".bak"; | ||
File blockingQueueDumpFile = new File(blockingQueueDumpFileName); | ||
if (blockingQueueDumpFile.exists() && !blockingQueueDumpFile.isDirectory()) { | ||
FileUtils.copyFile(blockingQueueDumpFile, new File(backupBlockingQueueDumpFileName)); | ||
} | ||
JAXBContext jaxbContext = JAXBContext.newInstance(ArtifactMetaInfoQueueDump.class); | ||
Marshaller marshaller = jaxbContext.createMarshaller(); | ||
ArtifactMetaInfoQueueDump artifactMetaInfoBlockingQueueDump = | ||
new ArtifactMetaInfoQueueDump(); | ||
artifactMetaInfoBlockingQueueDump.addAllArtifactMetaInfo(Sets.newHashSet(internalBlockingQueue)); | ||
marshaller.marshal(artifactMetaInfoBlockingQueueDump, blockingQueueDumpFile); | ||
} catch (Exception e) { | ||
log.error(e.getMessage(), e); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
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