Java Code Examples for org.apache.commons.lang3.exception.ExceptionUtils#rethrow()

The following examples show how to use org.apache.commons.lang3.exception.ExceptionUtils#rethrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceResource.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("stop_all")
public Response stopEnvironmentServices() {

    TestToolsAPI api = TestToolsAPI.getInstance();

    BiConsumer<ServiceName, IServiceNotifyListener> action = (serviceName, listener) -> {
        try {
            api.stopService(serviceName, false, listener);
        } catch (InterruptedException | ExecutionException e) {
            ExceptionUtils.rethrow(e);
        }
    };

    return processServices(env -> true, action);

}
 
Example 2
Source File: ServiceResource.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("stop_env")
public Response stopEnvironmentServices(@DefaultValue(ServiceName.DEFAULT_ENVIRONMENT) @QueryParam("environment") String environment) {

    TestToolsAPI api = TestToolsAPI.getInstance();

    BiConsumer<ServiceName, IServiceNotifyListener> action = (serviceName, listener) -> {
        try {
            api.stopService(serviceName, true, listener);
        } catch (InterruptedException | ExecutionException e) {
            ExceptionUtils.rethrow(e);
        }
    };

    return processServices(environment::equals, action);

}
 
Example 3
Source File: ServiceResource.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("start_all")
public Response startAllServices() {

    TestToolsAPI api = TestToolsAPI.getInstance();

    BiConsumer<ServiceName, IServiceNotifyListener> action = (serviceName, notifyListener) -> {
        try {
            api.startService(serviceName, true, notifyListener);
        } catch (InterruptedException | ExecutionException e) {
            ExceptionUtils.rethrow(e);
        }
    };

    return processServices(env -> true, action);

}
 
Example 4
Source File: ServiceResource.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("start_env")
public Response startEnvironmentServices(@DefaultValue(ServiceName.DEFAULT_ENVIRONMENT) @QueryParam("environment") String environment) {

    TestToolsAPI api = TestToolsAPI.getInstance();

    BiConsumer<ServiceName, IServiceNotifyListener> action = (serviceName, notifyListener) -> {
        try {
            api.startService(serviceName, true, notifyListener);
        } catch (InterruptedException | ExecutionException e) {
            ExceptionUtils.rethrow(e);
        }
    };

    return processServices(env -> env.equals(environment), action);

}
 
Example 5
Source File: LogConsumerUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        consumer.consume(record);
    } catch (Throwable e) {
        ExceptionUtils.rethrow(e);
    }
}
 
Example 6
Source File: StreamConsumerFactoryProvider.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs the {@link StreamConsumerFactory} using the {@link StreamConfig::getConsumerFactoryClassName()} property and initializes it
 * @param streamConfig
 * @return
 */
public static StreamConsumerFactory create(StreamConfig streamConfig) {
  StreamConsumerFactory factory = null;
  try {
    factory = PluginManager.get().createInstance(streamConfig.getConsumerFactoryClassName());
  } catch (Exception e) {
    ExceptionUtils.rethrow(e);
  }
  factory.init(streamConfig);
  return factory;
}
 
Example 7
Source File: DefaultConnectionManager.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ProhibitedExceptionCaught")
private <T> T withWriteLock(ReadWriteLock lock, CheckedSupplier<T> supplier) {
    try {
        lock.writeLock().lock();
        return supplier.get();
    } catch (Throwable t) {
        return ExceptionUtils.rethrow(t);
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example 8
Source File: DefaultConnectionManager.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ProhibitedExceptionCaught")
private <T> T withReadLock(ReadWriteLock lock, CheckedSupplier<T> supplier) {
    try {
        lock.readLock().lock();
        return supplier.get();
    } catch (Throwable t) {
        return ExceptionUtils.rethrow(t);
    } finally {
        lock.readLock().unlock();
    }
}
 
Example 9
Source File: ActionNameRetriever.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
private static String getMethodName(Class<? extends IActionCaller> clazz, CheckedConsumer<IActionCaller> method) throws Exception {
    try {
        IActionCallerProxy proxy = getProxy(clazz);
        method.accept(proxy);
        return proxy.getMethodName();
    } catch (Exception e) {
        throw e;
    } catch (@SuppressWarnings("ProhibitedExceptionCaught") Throwable t) {
        return ExceptionUtils.rethrow(t);
    }
}
 
Example 10
Source File: ServiceActions.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@CommonColumns(@CommonColumn(value = Column.ServiceName, required = true))
@ActionMethod
   public void initService(IActionContext actionContext, HashMap<?, ?> message) throws IllegalAccessException, InvocationTargetException, InterruptedException, IOException {
	ServiceName serviceName = ServiceName.parse(actionContext.getServiceName());
	IActionServiceManager serviceManager = actionContext.getServiceManager();

	try {
           IServiceSettings serviceSettings = serviceManager.getServiceSettings(serviceName);
		BeanMap beanMap = new BeanMap(serviceSettings);
		Set<String> editedProperty = new HashSet<>();
		Set<String> incorrectProperty = new HashSet<>();
		for (Entry<?, ?> entry : message.entrySet()) {
			String property = convertProperty(entry.getKey().toString());
			if (beanMap.containsKey(property)){
				BeanUtils.setProperty(serviceSettings, property, converter.get().convert((Object)unwrapFilters(entry.getValue()), beanMap.getType(property)));
                   editedProperty.add(property);
			} else {
				incorrectProperty.add(property);
			}
		}

		if (!incorrectProperty.isEmpty()) {
			throw new EPSCommonException(serviceSettings.getClass().getName() + " does not contain properties: " + incorrectProperty);
		}

           serviceManager.updateService(serviceName, serviceSettings, null).get();

		try (FileOutputStream out = new FileOutputStream(actionContext.getReport().createFile(StatusType.NA, servicesFolder, changingSettingFolder, serviceName + FORMATTER.format(DateTimeUtility.nowLocalDateTime()) + servicesFileExpression))) {
               actionContext.getServiceManager().serializeServiceSettings(serviceName, out);
           }
       } catch (ExecutionException e) {
           ExceptionUtils.rethrow(ObjectUtils.defaultIfNull(e.getCause(), e));
       }
}
 
Example 11
Source File: ZKGuidGenerator.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
@Override
public long next() {
    try {
        checkCache();

        return curGuid++;
    } catch (Exception e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 12
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
public static <T> T readFromInputStream(InputStream in, Class<T> clazz) {
    try {
        return getMapper().readValue(in, clazz);
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 13
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
public static void writeToOutputStream(OutputStream out, Object value) {
    try {
        getMapper().writeValue(out, value);
    } catch (IOException e) {
        ExceptionUtils.rethrow(e);
    }
}
 
Example 14
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 解析json字符串的字节数组为map对象。
 */
public static <M extends Map<?, ?>> M readMapFromJsonBytes(@Nonnull byte[] jsonBytes,
                                                           @Nonnull Class<M> mapClass,
                                                           @Nonnull Class<?> keyClass,
                                                           @Nonnull Class<?> valueClass) {
    ObjectMapper mapper = getMapper();
    MapType mapType = mapper.getTypeFactory().constructMapType(mapClass, keyClass, valueClass);
    try {
        return mapper.readValue(jsonBytes, mapType);
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 15
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 解析json字符串为map对象。
 */
public static <M extends Map> M readMapFromJson(@Nonnull String json,
                                                @Nonnull Class<M> mapClass,
                                                @Nonnull Class<?> keyClass,
                                                @Nonnull Class<?> valueClass) {
    ObjectMapper mapper = getMapper();
    MapType mapType = mapper.getTypeFactory().constructMapType(mapClass, keyClass, valueClass);
    try {
        return mapper.readValue(json, mapType);
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 16
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 解析json字符串对应的字节数组为java对象。
 */
public static <T> T readFromJsonBytes(@Nonnull byte[] jsonBytes, @Nonnull Class<T> clazz) {
    try {
        return getMapper().readValue(jsonBytes, clazz);
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 17
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 将bean转换为json对应的字节数组
 */
public static byte[] writeAsJsonBytes(@Nonnull Object bean) {
    try {
        return getMapper().writeValueAsBytes(bean);
    } catch (JsonProcessingException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 18
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 解析json字符串为java对象。
 */
public static <T> T readFromJson(@Nonnull String json, @Nonnull Class<T> clazz) {
    try {
        return getMapper().readValue(json, clazz);
    } catch (IOException e) {
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 19
Source File: JsonUtils.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * 将bean转换为json字符串
 */
public static String writeAsJson(@Nonnull Object bean) {
    try {
        return getMapper().writeValueAsString(bean);
    } catch (JsonProcessingException e) {
        // 之所以捕获,是因为,出现异常的地方应该是非常少的
        return ExceptionUtils.rethrow(e);
    }
}
 
Example 20
Source File: BinarySerializer.java    From fastjgame with Apache License 2.0 5 votes vote down vote up
/**
 * @param typeModelMapper 类型映射信息
 * @param filter          由于{@link BinarySerializer}支持的消息类是确定的,不能加入,但是允许过滤删除
 */
@SuppressWarnings("unchecked")
public static BinarySerializer newInstance(TypeModelMapper typeModelMapper, Predicate<Class<?>> filter) {
    final Set<Class<?>> supportedClassSet = getFilteredSupportedClasses(filter);
    final List<PojoCodecImpl<?>> codecList = new ArrayList<>(supportedClassSet.size());
    try {
        for (Class<?> messageClazz : supportedClassSet) {
            // protoBuf消息
            if (Message.class.isAssignableFrom(messageClazz)) {
                Parser<?> parser = ProtoUtils.findParser((Class<? extends Message>) messageClazz);
                codecList.add(new ProtoMessageCodec(messageClazz, parser));
                continue;
            }

            // protoBufEnum
            if (ProtocolMessageEnum.class.isAssignableFrom(messageClazz)) {
                final Internal.EnumLiteMap<?> mapper = ProtoUtils.findMapper((Class<? extends ProtocolMessageEnum>) messageClazz);
                codecList.add(new ProtoEnumCodec(messageClazz, mapper));
                continue;
            }

            // 带有DBEntity和SerializableClass注解的所有类,和手写Serializer的类
            final Class<? extends PojoCodecImpl<?>> serializerClass = CodecScanner.getCodecClass(messageClazz);
            if (serializerClass != null) {
                final PojoCodecImpl<?> codec = createCodecInstance(serializerClass);
                codecList.add(new CustomPojoCodec(codec));
                continue;
            }

            throw new IllegalArgumentException("Unsupported class " + messageClazz.getName());
        }

        final CodecRegistry codecRegistry = CodecRegistrys.fromAppPojoCodecs(typeModelMapper, codecList);
        return new BinarySerializer(codecRegistry);
    } catch (Exception e) {
        return ExceptionUtils.rethrow(e);
    }
}