use of org.apache.ignite.spi.deployment.uri.scanners.GridUriDeploymentScannerListener 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;
return name.toLowerCase().endsWith(".gar");
}
};
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 GAR units [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));
}
log.info("Found deleted GAR 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());
}
Aggregations