List of usage examples for io.vertx.core VertxException VertxException
public VertxException(Throwable cause)
From source file:com.github.mcollovati.vertx.Sync.java
License:Open Source License
public static <T> T await(Consumer<Handler<AsyncResult<T>>> task) { CountDownLatch countDownLatch = new CountDownLatch(1); try {//from w w w . j a v a 2s . co m Future<T> f = Future.<T>future().setHandler(ar -> { countDownLatch.countDown(); if (ar.failed()) { throw new VertxException(ar.cause()); } }); task.accept(f.completer()); countDownLatch.await(); return f.result(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new VertxException(e); } }
From source file:com.klwork.spring.vertx.render.MyStaticHandlerImpl.java
License:Open Source License
private Date parseDate(String header) { try {/*from www . j a v a2 s . com*/ return dateTimeFormatter.parse(header); } catch (ParseException e) { throw new VertxException(e); } }
From source file:com.tesco.mewbase.bson.BsonArray.java
License:Open Source License
/** * Encode the BSON object as a buffer/* w ww . j av a 2 s . com*/ * * @return the buffer */ public Buffer encode() { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); Bson.encode(list, os); os.flush(); return Buffer.buffer(os.toByteArray()); } catch (IOException e) { throw new VertxException(e); } }
From source file:com.tesco.mewbase.bson.BsonObject.java
License:Open Source License
public Buffer encode() { try {/*from ww w. j a va 2s . com*/ ByteArrayOutputStream os = new ByteArrayOutputStream(); Bson.encode(map, os); os.flush(); return Buffer.buffer(os.toByteArray()); } catch (IOException e) { throw new VertxException(e); } }
From source file:io.atomix.vertx.AtomixClusterManager.java
License:Apache License
@Override public void getLockWithTimeout(String name, long timeout, Handler<AsyncResult<Lock>> handler) { Context context = vertx.getOrCreateContext(); atomix.getLock(name).whenComplete((lock, error) -> { if (error == null) { lock.tryLock(Duration.ofMillis(timeout)).whenComplete((lockResult, lockError) -> { if (lockError == null) { if (lockResult == null) { context.runOnContext(v -> Future .<Lock>failedFuture(new VertxException("Timed out waiting to get lock " + name)) .setHandler(handler)); } else { context.runOnContext(v -> Future.<Lock>succeededFuture(new AtomixLock(vertx, lock)) .setHandler(handler)); }//ww w. j a v a 2 s . c o m } else { context.runOnContext(v -> Future.<Lock>failedFuture(lockError).setHandler(handler)); } }); } else { context.runOnContext(v -> Future.<Lock>failedFuture(error).setHandler(handler)); } }); }
From source file:io.atomix.vertx.ClusterSerializableSerializer.java
License:Apache License
@Override public T read(Class<T> type, BufferInput input, Serializer serializer) { try {// ww w.java2 s.com T object = type.newInstance(); byte[] bytes = new byte[input.readUnsignedShort()]; input.read(bytes); Buffer buffer = Buffer.buffer(bytes); object.readFromBuffer(0, buffer); return object; } catch (InstantiationException | IllegalAccessException e) { throw new VertxException("failed to instantiate serializable type: " + type); } }
From source file:io.reactiverse.pgclient.impl.PgPoolImpl.java
License:Apache License
public PgPoolImpl(Vertx vertx, boolean closeVertx, PgPoolOptions options) { int maxSize = options.getMaxSize(); if (maxSize < 1) { throw new IllegalArgumentException("Pool max size must be > 0"); }/* w ww . ja v a 2 s .c om*/ if (options.isUsingDomainSocket() && !vertx.isNativeTransportEnabled()) { throw new VertxException("Native transport is not available"); } this.context = vertx.getOrCreateContext(); this.factory = new PgConnectionFactory(context, Vertx.currentContext() != null, options); this.pool = new ConnectionPool(factory::create, maxSize, options.getMaxWaitQueueSize()); this.closeVertx = closeVertx; }
From source file:io.reactiverse.pgclient.impl.SocketConnection.java
License:Apache License
public void schedule(CommandBase<?> cmd) { if (cmd.handler == null) { throw new IllegalArgumentException(); }/* w w w. ja v a 2 s .c o m*/ if (Vertx.currentContext() != context) { throw new IllegalStateException(); } // Special handling for cache if (cmd instanceof PrepareStatementCommand) { PrepareStatementCommand psCmd = (PrepareStatementCommand) cmd; Map<String, SocketConnection.CachedPreparedStatement> psCache = this.psCache; if (psCache != null) { SocketConnection.CachedPreparedStatement cached = psCache.get(psCmd.sql); if (cached != null) { Handler<? super CommandResponse<PreparedStatement>> handler = psCmd.handler; cached.get(handler); return; } else { psCmd.statement = psSeq.next(); psCmd.cached = cached = new SocketConnection.CachedPreparedStatement(); psCache.put(psCmd.sql, cached); Handler<? super CommandResponse<PreparedStatement>> a = psCmd.handler; psCmd.cached.get(a); psCmd.handler = psCmd.cached; } } } // if (status == Status.CONNECTED) { pending.add(cmd); checkPending(); } else { cmd.fail(new VertxException("Connection not open " + status)); } }
From source file:io.reactiverse.pgclient.impl.SocketConnection.java
License:Apache License
private void handleClose(Throwable t) { if (status != Status.CLOSED) { status = Status.CLOSED;/*from w w w. ja v a2 s .c o m*/ if (t != null) { synchronized (this) { if (holder != null) { holder.handleException(t); } } } Throwable cause = t == null ? new VertxException("closed") : t; for (ArrayDeque<CommandBase<?>> q : Arrays.asList(inflight, pending)) { CommandBase<?> cmd; while ((cmd = q.poll()) != null) { CommandBase<?> c = cmd; context.runOnContext(v -> c.fail(cause)); } } if (holder != null) { holder.handleClosed(); } } }
From source file:io.reactiverse.pgclient.impl.Transaction.java
License:Apache License
private synchronized void checkPending() { switch (status) { case ST_BEGIN: break;/*from www . j av a2s . com*/ case ST_PENDING: { CommandBase<?> cmd = pending.poll(); if (cmd != null) { if (isComplete(cmd)) { status = ST_COMPLETED; } else { wrap(cmd); status = ST_PROCESSING; } doSchedule(cmd); } break; } case ST_PROCESSING: break; case ST_COMPLETED: { if (pending.size() > 0) { VertxException err = new VertxException("Transaction already completed"); CommandBase<?> cmd; while ((cmd = pending.poll()) != null) { cmd.fail(err); } } break; } } }