use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class CacheHibernateBlobStore method init.
/**
* Initializes store.
*
* @throws IgniteException If failed to initialize.
*/
private void init() throws IgniteException {
if (initGuard.compareAndSet(false, true)) {
if (log.isDebugEnabled())
log.debug("Initializing cache store.");
try {
if (sesFactory != null)
// Session factory has been provided - nothing to do.
return;
if (!F.isEmpty(hibernateCfgPath)) {
try {
URL url = new URL(hibernateCfgPath);
sesFactory = new Configuration().configure(url).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using URL: " + url);
// Session factory has been successfully initialized.
return;
} catch (MalformedURLException e) {
if (log.isDebugEnabled())
log.debug("Caught malformed URL exception: " + e.getMessage());
}
// Provided path is not a valid URL. File?
File cfgFile = new File(hibernateCfgPath);
if (cfgFile.exists()) {
sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using file: " + hibernateCfgPath);
// Session factory has been successfully initialized.
return;
}
// Provided path is not a file. Classpath resource?
sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
} else {
if (hibernateProps == null) {
U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
hibernateProps = new Properties();
hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
}
Configuration cfg = new Configuration();
cfg.setProperties(hibernateProps);
assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
cfg.addResource(MAPPING_RESOURCE);
sesFactory = cfg.buildSessionFactory();
if (log.isDebugEnabled())
log.debug("Configured session factory using properties: " + hibernateProps);
}
} catch (HibernateException e) {
throw new IgniteException("Failed to initialize store.", e);
} finally {
initLatch.countDown();
}
} else if (initLatch.getCount() > 0) {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
if (sesFactory == null)
throw new IgniteException("Cache store was not properly initialized.");
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class TcpDiscoveryKubernetesIpFinder method init.
/**
* Kubernetes IP finder initialization.
*
* @throws IgniteSpiException In case of error.
*/
private void init() throws IgniteSpiException {
if (initGuard.compareAndSet(false, true)) {
if (serviceName == null || serviceName.isEmpty() || namespace == null || namespace.isEmpty() || master == null || master.isEmpty() || accountToken == null || accountToken.isEmpty()) {
throw new IgniteSpiException("One or more configuration parameters are invalid [setServiceName=" + serviceName + ", setNamespace=" + namespace + ", setMasterUrl=" + master + ", setAccountToken=" + accountToken + "]");
}
try {
// Preparing the URL and SSL context to be used for connection purposes.
String path = String.format("/api/v1/namespaces/%s/endpoints/%s", namespace, serviceName);
url = new URL(master + path);
ctx = SSLContext.getInstance("SSL");
ctx.init(null, trustAll, new SecureRandom());
} catch (Exception e) {
throw new IgniteSpiException("Failed to connect to Ignite's Kubernetes Service.", e);
} finally {
initLatch.countDown();
}
} else {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
if (url == null || ctx == null)
throw new IgniteSpiException("IP finder has not been initialized properly.");
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.
/**
* @throws Exception If failed.
*/
public void testFlowSend() throws Exception {
reject = true;
final CyclicBarrier barrier = new CyclicBarrier(THREAD_CNT);
final Random rnd = new Random();
final ClusterNode from = randomNode(rnd);
ClusterNode tmp;
do {
tmp = randomNode(rnd);
} while (tmp.id().equals(from.id()));
final ClusterNode to = tmp;
final int iterationCnt = 1000;
final AtomicInteger threadId = new AtomicInteger();
final int interval = 50;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
/** {@inheritDoc} */
@Override
public void run() {
try {
// Only first thread will print messages.
int id = threadId.getAndIncrement();
for (int i = 0; i < iterationCnt; i++) {
if (id == 0 && (i % 50) == 0)
info(">>> Running iteration " + i);
try {
for (ClusterNode node : nodes) {
Message msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0);
spis.get(from.id()).sendMessage(node, msg);
}
} catch (IgniteException e) {
log.warning(">>> Oops, unable to send message (safe to ignore).", e);
}
barrier.await();
}
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
} catch (BrokenBarrierException e) {
info("Wait on barrier failed: " + e);
Thread.currentThread().interrupt();
}
}
}, THREAD_CNT, "message-sender");
final AtomicBoolean run = new AtomicBoolean(true);
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
while (run.get() && !Thread.currentThread().isInterrupted()) {
U.sleep(interval * 3 / 2);
((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.id());
}
} catch (IgniteInterruptedCheckedException ignored) {
Thread.currentThread().interrupt();
}
}
}, 1);
fut.get();
run.set(false);
fut2.get();
// Wait when all messages are acknowledged to do not break next tests' logic.
for (CommunicationSpi<Message> spi : spis.values()) {
GridNioServer srv = U.field(spi, "nioSrvr");
Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
for (GridNioSession ses : sessions) {
final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
if (snd != null) {
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return snd.messagesRequests().isEmpty();
}
}, 10_000);
assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
}
}
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException 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());
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class CacheLockImpl method tryLock.
/** {@inheritDoc} */
@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
if (time <= 0)
return tryLock();
CacheOperationContext prev = gate.enter(opCtx);
try {
checkTx();
IgniteInternalFuture<Boolean> fut = delegate.lockAllAsync(keys, unit.toMillis(time));
try {
boolean res = fut.get();
if (res)
incrementLockCounter();
return res;
} catch (IgniteInterruptedCheckedException e) {
if (!fut.cancel()) {
if (fut.isDone()) {
Boolean res = fut.get();
Thread.currentThread().interrupt();
if (res)
incrementLockCounter();
return res;
}
}
if (e.getCause() instanceof InterruptedException)
throw (InterruptedException) e.getCause();
throw new InterruptedException();
}
} catch (IgniteCheckedException e) {
throw new CacheException(e.getMessage(), e);
} finally {
gate.leave(prev);
}
}
Aggregations