use of org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScannerManager in project ignite by apache.
the class UriDeploymentSpi method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
// Start SPI start stopwatch.
startStopwatch();
assertParameter(uriList != null, "uriList != null");
initializeUriList();
if (uriEncodedList.isEmpty())
addDefaultUri();
initializeTemporaryDirectoryPath();
registerMBean(igniteInstanceName, new UriDeploymentSpiMBeanImpl(this), UriDeploymentSpiMBean.class);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
assert name != null;
String nameLowerCase = name.toLowerCase();
return nameLowerCase.endsWith(".gar") || nameLowerCase.endsWith(".jar");
}
};
firstScanCntr = 0;
GridUriDeploymentScannerListener lsnr = new GridUriDeploymentScannerListener() {
@Override
public void onNewOrUpdatedFile(File file, String uri, long tstamp) {
if (log.isInfoEnabled())
log.info("Found new or updated deployment unit [uri=" + U.hidePassword(uri) + ", file=" + file.getAbsolutePath() + ", tstamp=" + tstamp + ']');
if (delayOnNewOrUpdatedFile) {
U.warn(log, "Delaying onNewOrUpdatedFile() by 10000 ms since 'delayOnNewOrUpdatedFile' " + "is set to true (is this intentional?).");
try {
U.sleep(10000);
} catch (IgniteInterruptedCheckedException ignored) {
// No-op
}
U.warn(log, "Delay finished.");
}
try {
GridUriDeploymentFileProcessorResult fileRes = GridUriDeploymentFileProcessor.processFile(file, uri, new File(deployTmpDirPath), log);
if (fileRes != null)
newUnitReceived(uri, fileRes.getFile(), tstamp, fileRes.getClassLoader(), fileRes.getTaskClasses(), fileRes.getMd5());
} catch (IgniteSpiException e) {
U.error(log, "Error when processing file: " + file.getAbsolutePath(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public void onDeletedFiles(List<String> uris) {
if (log.isInfoEnabled()) {
List<String> uriList = null;
if (uris != null) {
uriList = new ArrayList<>();
for (String uri : uris) uriList.add(U.hidePassword(uri));
}
if (log.isInfoEnabled())
log.info("Found deleted deployment units [uris=" + uriList + ']');
}
processDeletedFiles(uris);
}
/**
* {@inheritDoc}
*/
@Override
public void onFirstScanFinished() {
synchronized (mux) {
firstScanCntr++;
if (isFirstScanFinished(firstScanCntr))
mux.notifyAll();
}
}
};
// Set default scanners if none are configured.
if (scanners == null) {
scanners = new UriDeploymentScanner[2];
scanners[0] = new UriDeploymentFileScanner();
scanners[1] = new UriDeploymentHttpScanner();
}
for (URI uri : uriEncodedList) {
File file = new File(deployTmpDirPath);
long freq = -1;
try {
freq = getFrequencyFromUri(uri);
} catch (NumberFormatException e) {
U.error(log, "Error parsing parameter value for frequency.", e);
}
UriDeploymentScannerManager mgr = null;
for (UriDeploymentScanner scanner : scanners) {
if (scanner.acceptsURI(uri)) {
mgr = new UriDeploymentScannerManager(igniteInstanceName, uri, file, freq > 0 ? freq : scanner.getDefaultScanFrequency(), filter, lsnr, log, scanner);
break;
}
}
if (mgr == null)
throw new IgniteSpiException("Unsupported URI (please configure appropriate scanner): " + uri);
mgrs.add(mgr);
mgr.start();
}
// Ack parameters.
if (log.isDebugEnabled()) {
log.debug(configInfo("tmpDirPath", tmpDirPath));
log.debug(configInfo("uriList", uriList));
log.debug(configInfo("encodeUri", encodeUri));
log.debug(configInfo("scanners", mgrs));
}
// Ack ok start.
if (log.isDebugEnabled())
log.debug(startInfo());
}
use of org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScannerManager in project ignite by apache.
the class UriDeploymentSpi method spiStop.
/**
* {@inheritDoc}
*/
@Override
public void spiStop() throws IgniteSpiException {
for (UriDeploymentScannerManager mgr : mgrs) mgr.cancel();
for (UriDeploymentScannerManager mgr : mgrs) mgr.join();
// Clear inner collections.
uriEncodedList.clear();
mgrs.clear();
List<ClassLoader> tmpClsLdrs;
// Release all class loaders.
synchronized (mux) {
tmpClsLdrs = new ArrayList<>(unitLoaders.size());
for (GridUriDeploymentUnitDescriptor desc : unitLoaders) tmpClsLdrs.add(desc.getClassLoader());
}
for (ClassLoader ldr : tmpClsLdrs) onUnitReleased(ldr);
// Delete temp directory.
if (deployTmpDirPath != null)
U.delete(new File(deployTmpDirPath));
unregisterMBean();
// Ack ok stop.
if (log.isDebugEnabled())
log.debug(stopInfo());
}
Aggregations