use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.
the class TestClassLoader method createTestBiz.
private Biz createTestBiz(String bizIdentity) {
String[] bizNameAndVersion = bizIdentity.split(":");
if (bizNameAndVersion.length != 2) {
throw new ArkRuntimeException("error bizIdentity format.");
}
BizManagerService bizManagerService = ArkServiceContainerHolder.getContainer().getService(BizManagerService.class);
Biz testBiz = new BizModel().setBizName(bizNameAndVersion[0]).setBizVersion(bizNameAndVersion[1]).setClassLoader(this).setDenyImportPackages("").setDenyImportClasses("").setDenyImportResources("").setBizState(BizState.RESOLVED);
bizManagerService.registerBiz(testBiz);
return testBiz;
}
use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.
the class DefaultBizDeployer method unDeploy.
@Override
public void unDeploy() {
for (Biz biz : bizManagerService.getBizInOrder()) {
try {
LOGGER.info(String.format("Begin to stop biz: %s", biz.getBizName()));
biz.stop();
LOGGER.info(String.format("Finish to stop biz: %s", biz.getBizName()));
} catch (Throwable e) {
LOGGER.error(String.format("stop biz: %s meet error", biz.getBizName()), e);
throw new ArkRuntimeException(e);
}
}
}
use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.
the class DefaultBizDeployer method deploy.
@Override
public void deploy() {
for (Biz biz : bizManagerService.getBizInOrder()) {
try {
LOGGER.info(String.format("Begin to start biz: %s", biz.getBizName()));
biz.start(arguments);
LOGGER.info(String.format("Finish to start biz: %s", biz.getBizName()));
} catch (Throwable e) {
LOGGER.error(String.format("Start biz: %s meet error", biz.getBizName()), e);
throw new ArkRuntimeException(e);
}
}
}
use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.
the class ExtensionLoaderServiceImpl method loadExtension.
private <I, L> Set<ExtensionClass<I, L>> loadExtension(Class<I> interfaceType, String extensionName, L location, ClassLoader resourceLoader) throws Throwable {
BufferedReader reader = null;
try {
Set<ExtensionClass<I, L>> extensionClassSet = new HashSet<>();
Extensible extensible = interfaceType.getAnnotation(Extensible.class);
if (extensible == null) {
throw new ArkRuntimeException(String.format("Extensible class %s is not annotated by %s.", interfaceType, Extensible.class));
}
String fileName = interfaceType.getCanonicalName();
if (!StringUtils.isEmpty(extensible.file())) {
fileName = extensible.file();
}
Enumeration<URL> enumeration = resourceLoader.getResources(EXTENSION_FILE_DIR + fileName);
while (enumeration.hasMoreElements()) {
URL url = enumeration.nextElement();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Loading extension of extensible: {} from location: {} and file: {}", interfaceType, location, url);
}
reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
ExtensionClass<I, L> extensionClass = new ExtensionClass<>();
extensionClass.setDefinedLocation(location);
extensionClass.setExtensible(extensible);
extensionClass.setInterfaceClass(interfaceType);
Class<?> implementClass = null;
String clazzName = line.trim();
try {
implementClass = resourceLoader.loadClass(clazzName);
} catch (Exception e) {
if (ArkConfigs.isEmbedEnable() && resourceLoader != ArkClient.getMasterBiz().getBizClassLoader()) {
implementClass = ArkClient.getMasterBiz().getBizClassLoader().loadClass(clazzName);
} else {
throw e;
}
}
if (!interfaceType.isAssignableFrom(implementClass)) {
throw new ArkRuntimeException(String.format("Extension implementation class %s is not type of %s.", implementClass.getCanonicalName(), interfaceType.getCanonicalName()));
}
Extension extension = implementClass.getAnnotation(Extension.class);
if (extension == null) {
throw new ArkRuntimeException(String.format("Extension implementation class %s is not annotated by %s.", implementClass, Extension.class));
}
if (!extensionName.equals(extension.value())) {
continue;
}
extensionClass.setExtension(extension);
extensionClass.setImplementClass((Class<I>) implementClass);
extensionClassSet.add(extensionClass);
}
}
return extensionClassSet;
} catch (Throwable throwable) {
LOGGER.error("Loading extension files from {} occurs an error {}.", location, throwable);
throw throwable;
} finally {
if (reader != null) {
reader.close();
}
}
}
use of com.alipay.sofa.ark.exception.ArkRuntimeException in project sofa-ark by alipay.
the class ArkContainer method main.
public static Object main(String[] args) throws ArkRuntimeException {
if (args.length < MINIMUM_ARGS_SIZE) {
throw new ArkRuntimeException("Please provide suitable arguments to continue !");
}
try {
LaunchCommand launchCommand = LaunchCommand.parse(args);
if (launchCommand.isExecutedByCommandLine()) {
ExecutableArkBizJar executableArchive;
File rootFile = new File(URLDecoder.decode(launchCommand.getExecutableArkBizJar().getFile()));
if (rootFile.isDirectory()) {
executableArchive = new ExecutableArkBizJar(new ExplodedArchive(rootFile));
} else {
executableArchive = new ExecutableArkBizJar(new JarFileArchive(rootFile, launchCommand.getExecutableArkBizJar()));
}
return new ArkContainer(executableArchive, launchCommand).start();
} else {
ClassPathArchive classPathArchive;
if (ArkConfigs.isEmbedEnable()) {
classPathArchive = new EmbedClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
} else {
classPathArchive = new ClassPathArchive(launchCommand.getEntryClassName(), launchCommand.getEntryMethodName(), launchCommand.getClasspath());
}
return new ArkContainer(classPathArchive, launchCommand).start();
}
} catch (IOException e) {
throw new ArkRuntimeException(String.format("SOFAArk startup failed, commandline=%s", LaunchCommand.toString(args)), e);
}
}
Aggregations