use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class ProcedureExecutionParentImpl method execute.
@Override
public void execute() throws TranslatorException {
String name = getCommand().getMetadataObject().getSourceName();
if (name == null) {
name = getCommand().getProcedureName();
}
if (GET_UPDATED.equalsIgnoreCase(name)) {
execution = new GetUpdatedExecutionImpl(this);
} else if (GET_DELETED.equalsIgnoreCase(name)) {
execution = new GetDeletedExecutionImpl(this);
} else {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TeiidRuntimeException("Unknown procedure " + getCommand().getProcedureName() + " with name in source " + name);
}
execution.execute(this);
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class SolrExecutionFactory method convertFromSolrType.
public Object convertFromSolrType(final Object value, final Class<?> expectedType) {
if (value == null) {
return null;
}
if (expectedType.isInstance(value)) {
return value;
}
try {
if (expectedType.isArray()) {
ArrayList multiValues = (ArrayList) value;
Object transformed = Array.newInstance(expectedType.getComponentType(), multiValues.size());
for (int i = 0; i < multiValues.size(); i++) {
Object obj = multiValues.get(i);
if (obj == null) {
Array.set(transformed, i, obj);
continue;
}
if (expectedType.getComponentType().isInstance(obj)) {
Array.set(transformed, i, obj);
continue;
}
if (DataTypeManager.isTransformable(obj.getClass(), expectedType.getComponentType())) {
Array.set(transformed, i, DataTypeManager.transformValue(obj, expectedType.getComponentType()));
} else {
throw new TeiidRuntimeException(SolrPlugin.Event.TEIID20001, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20001, value, expectedType.getName()));
}
}
return transformed;
}
if (DataTypeManager.isTransformable(value.getClass(), expectedType)) {
return DataTypeManager.transformValue(value, expectedType);
}
throw new TeiidRuntimeException(SolrPlugin.Event.TEIID20001, SolrPlugin.Util.gs(SolrPlugin.Event.TEIID20001, value, expectedType.getName()));
} catch (TransformationException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class DataTierTupleSource method asynchGet.
private AtomicResultsMessage asynchGet() throws BlockedException, TeiidProcessingException, TeiidComponentException, TranslatorException {
if (futureResult == null) {
addWork();
}
if (!futureResult.isDone()) {
// $NON-NLS-1$
throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking on source query", aqr.getAtomicRequestID());
}
FutureWork<AtomicResultsMessage> currentResults = futureResult;
futureResult = null;
AtomicResultsMessage results = null;
try {
results = currentResults.get();
if (results.getFinalRow() < 0) {
addWork();
}
} catch (CancellationException e) {
throw new TeiidProcessingException(e);
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30503, e);
} catch (ExecutionException e) {
if (e.getCause() instanceof TeiidProcessingException) {
throw (TeiidProcessingException) e.getCause();
}
if (e.getCause() instanceof TeiidComponentException) {
throw (TeiidComponentException) e.getCause();
}
if (e.getCause() instanceof TranslatorException) {
throw (TranslatorException) e.getCause();
}
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
// shouldn't happen
throw new RuntimeException(e);
}
return results;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class BufferFrontedFileStoreCache method evictFromMemoryBuffer.
/**
* Eviction routine. When space is exhausted data blocks are acquired from
* memory entries.
* @param acquire
* @return
*/
int evictFromMemoryBuffer(boolean acquire) {
boolean writeLocked = false;
int next = EMPTY_ADDRESS;
try {
for (int i = 0; i < EVICTION_SCANS && next == EMPTY_ADDRESS; i++) {
// doing a cleanup may trigger the purging of resources
AutoCleanupUtil.doCleanup(true);
// scan the eviction queue looking for a victim
Iterator<PhysicalInfo> iter = memoryBufferEntries.getEvictionQueue().iterator();
while (((!acquire && lowBlocks(false)) || (acquire && (next = blocksInuse.getAndSetNextClearBit()) == EMPTY_ADDRESS)) && iter.hasNext()) {
PhysicalInfo info = iter.next();
synchronized (info) {
if (info.inode == EMPTY_ADDRESS) {
continue;
}
if (info.pinned || info.evicting) {
if (!acquire || i != EVICTION_SCANS - 1) {
continue;
}
if (acquire && !writeLocked) {
// stop the world - prevent any other thread from taking a free block
// until this one is satisfied
memoryEvictionLock.writeLock().lock();
writeLocked = true;
}
// wait for the read/eviction to be over
info.await(true, true);
if (info.inode == EMPTY_ADDRESS) {
continue;
}
}
// mark as evicting early so that other evictFromMemoryCalls don't select this same entry
info.evicting = true;
}
next = free(info, true, acquire);
break;
}
}
if (acquire && next == EMPTY_ADDRESS) {
if (!writeLocked) {
memoryEvictionLock.writeLock().lock();
writeLocked = true;
}
freedLock.lock();
try {
long waitTime = TIMEOUT_NANOS;
while (true) {
next = blocksInuse.getAndSetNextClearBit();
if (next != EMPTY_ADDRESS) {
return next;
}
waitTime = blocksFreed.awaitNanos(waitTime);
if (waitTime <= 0) {
break;
}
}
} finally {
freedLock.unlock();
}
next = blocksInuse.getAndSetNextClearBit();
if (next == EMPTY_ADDRESS) {
// $NON-NLS-1$
throw new AssertionError("Could not free space for pending write");
}
}
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30050, e);
} finally {
if (writeLocked) {
memoryEvictionLock.writeLock().unlock();
}
}
return next;
}
use of org.teiid.core.TeiidRuntimeException in project teiid by teiid.
the class BufferFrontedFileStoreCache method get.
@Override
public CacheEntry get(PhysicalInfo info, Long oid, WeakReference<? extends Serializer<?>> ref) throws TeiidComponentException {
if (info == null) {
return null;
}
Serializer<?> serializer = ref.get();
if (serializer == null) {
return null;
}
readAttempts.incrementAndGet();
InputStream is = null;
Lock lock = null;
ExtensibleBufferedInputStream eis = null;
int memoryBlocks = 0;
try {
synchronized (info) {
// load should be locked
assert !info.pinned && info.loading;
// not necessary, but should make things safer
info.await(true, false);
if (info.inode != EMPTY_ADDRESS) {
info.pinned = true;
memoryBufferEntries.touch(info);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at inode", info.inode, serializer.getId(), oid);
}
BlockManager manager = getBlockManager(serializer.getId(), oid, info.inode);
is = new BlockInputStream(manager, info.memoryBlockCount);
} else if (info.block != EMPTY_ADDRESS) {
info.pinned = true;
memoryBufferEntries.recordAccess(info);
storageReads.incrementAndGet();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Getting object at block", info.block, info.sizeIndex, serializer.getId(), oid);
}
BlockStore blockStore = sizeBasedStores[info.sizeIndex];
int segment = info.block / blockStore.blocksInUse.getBitsPerSegment();
FileStore fs = blockStore.stores[segment];
long blockOffset = (info.block % blockStore.blocksInUse.getBitsPerSegment()) * blockStore.blockSize;
eis = fs.createInputStream(blockOffset, info.memoryBlockCount << LOG_BLOCK_SIZE);
lock = blockStore.locks[segment].writeLock();
memoryBlocks = info.memoryBlockCount;
} else {
return null;
}
}
if (lock != null) {
is = readIntoMemory(info, eis, lock, memoryBlocks);
}
for (int i = 0; i < HEADER_BYTES; i++) {
is.read();
}
ObjectInput dis = new ObjectInputStream(is);
CacheEntry ce = new CacheEntry(new CacheKey(oid, 1, 1), info.sizeEstimate, serializer.deserialize(dis), ref, true);
return ce;
} catch (IOException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
} catch (ClassNotFoundException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30048, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30048, info.gid, oid));
} catch (InterruptedException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30049, e);
} finally {
synchronized (info) {
info.pinned = false;
info.notifyAll();
}
}
}
Aggregations