public void setTransactionTimeout(long timeout) throws BagriException { if (timeout < 0) { throw new BagriException("negative timeout value is not supported", BagriException.ecTransaction); } this.txTimeout = timeout; }
/** * {@inheritDoc} */ @Override public ParseResults parse(File file) throws BagriException { try (Reader reader = new FileReader(file)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
/** * {@inheritDoc} */ @Override public ParseResults parse(String xml) throws BagriException { try (Reader reader = new StringReader(xml)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
public void checkClusterState() throws BagriException { if (checkState != HealthCheckState.skip) { if (!isClusterSafe()) { if (checkState == HealthCheckState.raise) { throw new BagriException("System is not healthy", BagriException.ecHealth); } else { // log unhealthy time here? logger.warn("System is not healthy"); } } } }
/** * {@inheritDoc} */ @Override public ParseResults parse(String json) throws BagriException { try (Reader reader = new StringReader(json)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
/** * {@inheritDoc} */ @Override public ParseResults parse(File file) throws BagriException { try (Reader reader = new FileReader(file)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
private DocumentAccessor runSimpleDocumentTask(Callable<DocumentAccessor> task, Properties props) throws BagriException { //checkDocumentProperties(props); Future<DocumentAccessor> future = execService.submit(task); try { DocumentAccessor result = future.get(); logger.trace("storeDocument.exit; returning: {}", result); return (DocumentAccessor) result; } catch (InterruptedException | ExecutionException ex) { // the document could be processed anyway.. logger.error("runSimpleDocumentTask.error", ex); throw new BagriException(ex, ecDocument); } }
/** * {@inheritDoc} */ public InputStream buildStream(Collection<Data> elements) throws BagriException { C content = buildContent(elements); if (content != null) { try { return new ByteArrayInputStream(((String) content).getBytes(def_encoding)); } catch (UnsupportedEncodingException ex) { throw new BagriException(ex, BagriException.ecInOut); } } return null; }
public static void main(String[] args) throws Exception { if (args.length < 4) { throw new BagriException("wrong number of arguments passed. Expected: schemaAddress schemaName userName password", 0); } Properties props = new Properties(); props.setProperty(pn_schema_address, args[0]); props.setProperty(pn_schema_name, args[1]); props.setProperty(pn_schema_user, args[2]); props.setProperty(pn_schema_password, args[3]); XDMClientApp client = new XDMClientApp(props); tester.testClient(client); }
@Override public ParseResults parse(InputStream stream) throws BagriException { JsonParser jParser = null; try { jParser = factory.createParser(stream); return parse(jParser); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } finally { closeParser(jParser); } }
@Override public ParseResults parse(String json) throws BagriException { JsonParser jParser = null; try { jParser = factory.createParser(json); return parse(jParser); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } finally { closeParser(jParser); } }
@Override public ParseResults parse(File file) throws BagriException { JsonParser jParser = null; try { jParser = factory.createParser(file); return parse(jParser); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } finally { closeParser(jParser); } }
@Override public ParseResults parse(Reader reader) throws BagriException { JsonParser jParser = null; try { jParser = factory.createParser(reader); return parse(jParser); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } finally { closeParser(jParser); } }
private String[] extractResult(XQResultSequence sequence, Properties props) throws BagriException { try { List<String> buff = new ArrayList<>(); if (sequence.first()) { do { buff.add(sequence.getItemAsString(props)); } while (sequence.next()); } return buff.toArray(new String[buff.size()]); } catch (Exception ex) { logger.error("extractResult.error", ex); throw new BagriException(ex, BagriException.ecQuery); } }
@Override public DocumentAccessor removeDocument(String uri, Properties props) throws BagriException { logger.trace("removeDocument.enter; uri: {}", uri); if (uri == null) { throw new BagriException("No Document URI passed", BagriException.ecDocument); } Document doc = getDocument(uri); if (doc == null) { logger.info("removeDocument; no active document found for uri: {}", uri); return null; } DocumentKey docKey = factory.newDocumentKey(doc.getDocumentKey()); return removeDocumentInternal(docKey, doc, props); }
@Override public void registerModelUri(String modelUri) throws BagriException { try { JsonReader reader = factory.createReader(new FileInputStream(modelUri)); JsonObject schema = reader.readObject(); processModel(schema); reader.close(); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
public ParseResults parse(JsonParser parser) throws BagriException { logger.trace("parse.enter; context: {}; schema: {}", parser.getParsingContext(), parser.getSchema()); ParserContext ctx = initContext(); try { while (parser.nextToken() != null) { processToken(ctx, parser); } } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } return ctx.getParseResults(); }
@Override public <T> ResultCursor<DocumentAccessor> storeDocuments(Map<String, T> documents, Properties props) throws BagriException { logger.trace("storeDocuments.enter; documents: {}; props: {}", documents, props); if (documents == null || documents.isEmpty()) { throw new BagriException("Empty Document collection provided", ecDocument); } repo.getHealthManagement().checkClusterState(); props = checkDocumentProperties(props); DocumentsCreator task = new DocumentsCreator(repo.getClientId(), repo.getTransactionId(), props, (Map<String, Object>) documents); // TODO: split documents between members properly.. ResultCursor<DocumentAccessor> result = runIterableDocumentTask(task, props); logger.trace("storeDocuments.exit; results: {}", result); return result; }
@Override public <T> DocumentAccessor storeDocument(String uri, T content, Properties props) throws BagriException { logger.trace("storeDocument.enter; uri: {}; content: {}; props: {}", uri, content, props); if (content == null) { throw new BagriException("Document content can not be null", ecDocument); } repo.getHealthManagement().checkClusterState(); props = checkDocumentProperties(props); DocumentCreator task = new DocumentCreator(repo.getClientId(), repo.getTransactionId(), props, uri, repo.getDistributionStrategy(), content); task.setRepository(repo); DocumentAccessor result = runSimpleDocumentTask(task, props); logger.trace("storeDocument.exit; returning: {}", result); return result; }
private Object getDocumentContent(DocumentKey docKey) throws BagriException { Object content = ddSvc.getCachedObject(CN_XDM_CONTENT, docKey, binaryContent); if (compressContent) { InternalSerializationService ss = ddSvc.getSerializationService(); byte[] buff = IOUtil.decompress((byte[]) content); ObjectDataInput odi = ss.createObjectDataInput(buff); try { content = odi.readObject(); } catch (IOException ex) { throw new BagriException(ex, ecDocument); } } return content; }