Vertx stop method not executed on service stop - vert.x

When I stop the service the stop is not getting called but if try the same in test case where I deploy and undeploy verticle with deployment ID the stop method is executing.
EDIT:-
I am creating jar file (not a shadow Jar).
Below is build.gradle configuration
application{
mainClassName='io.vertx.core.Launcher'
}
def mainVerticleName = 'verticleName'
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "$mainVerticleName",
"Main-Class": "io.vertx.core.Launcher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}
starting application :-
java -jar api-gateway-1.0.0-SNAPSHOT.jar -Dconfig.propertyFile="<property file path>" -DlogfilePath="<log file path>"
stopping application :-
CTRL+C

Creating CustomLauncher extending Launcher class worked.
#Log4j2
public class CustomLauncher extends Launcher {
public static void main(String[] args) {
new CustomLauncher().dispatch(args);
}
#Override
public void beforeStoppingVertx(Vertx vertx) {
log.info(" beforeStoppingVertx Called ===========");
cleanUPBeforeStoppingVerx();
}
#Override
public void afterStoppingVertx() {
log.info(" afterStoppingVertx Called ===========");
}
#Override
public void beforeDeployingVerticle(DeploymentOptions deploymentOptions) {
log.info(" beforeDeployingVerticle Called ===========");
}
#Override
public void beforeStartingVertx(VertxOptions options) {
log.info(" beforeStartingVertx Called ===========");
}
#Override
public void afterStartingVertx(Vertx vertx) {
log.info(" afterStartingVertx Called ===========");
}
#Override
public void handleDeployFailed(Vertx vertx, String mainVerticle, DeploymentOptions deploymentOptions,
Throwable cause) {
log.info("handleDeployFailed *****************");
vertx.close();
}
}
build.gradle changes :-
jar {
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Verticle": "LauncherVerticle",
"Main-Class": "CustomLauncher",
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
)
}
}

Related

Apache Storm Problem: "Unable to canonicalize address localhost/<unresolved>:2000 because it's not resolvable"

When I launch a simple Strorm script on IntellijIdea or Eclipse i encounter this problem: "Unable to canonicalize address localhost/:2000 because it's not resolvable".
import org.apache.storm.*;
import org.apache.storm.generated.*;
import org.apache.storm.spout.SpoutOutputCollector;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.TopologyBuilder;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.topology.base.BaseRichSpout;
import org.apache.storm.tuple.*;
import org.apache.storm.utils.Utils;
import java.util.Map;
import java.util.Random;
public class ExclamationExample {
public static class TestWordSpout extends BaseRichSpout {
private SpoutOutputCollector _collector;
#Override
public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
_collector = spoutOutputCollector;
}
#Override
public void nextTuple() {
Utils.sleep(100);
final String[] words = new String[]{"nathan", "mike", "jackson", "golda", "bertels"};
final Random rand = new Random();
final String word = words[rand.nextInt(words.length)];
_collector.emit(new Values(word));
System.out.printf("Word spout: %s\n", word);
}
#Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
outputFieldsDeclarer.declare(new Fields("word"));
}
}
public static class ExclamationBolt extends BaseRichBolt {
private OutputCollector collector;
#Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
this.collector = collector;
}
#Override
public void execute(Tuple tuple) {
String val = tuple.getString(0) + "!!!";
collector.emit(tuple, new Values(val));
System.out.printf("Exclamation bolt: %s\n", val);
collector.ack(tuple);
}
#Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
declarer.declare(new Fields("word"));
}
}
//TOPOLOGY
public static void main(String[] args) throws Exception {
Config conf = new Config();
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new TestWordSpout(), 2);
builder.setBolt("exclaim1", new ExclamationBolt(), 2).shuffleGrouping("word");
builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
conf.setDebug(false);
String topologyName = "test";
conf.setNumWorkers(2);
//If there are arguments, we are running on a cluster
if (args != null && args.length > 0) {
conf.setNumWorkers(3);
topologyName = args[0];
StormSubmitter.submitTopology(topologyName, conf, builder.createTopology());
}
try (LocalCluster cluster = new LocalCluster()) {
cluster.submitTopology(topologyName, conf, builder.createTopology());
Utils.sleep(600000); // wait [param] ms
cluster.killTopology(topologyName);
cluster.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
What is a possible solution?
I resolved my problem. If can help someone i tell the solution. I ran the Java Application using Java SDK 17, this give me problem, then I created new project with JDK 1.8 and everything works!

Flutter Plugin - cannot resolve method 'startActivityForResult'

Recently I am working on a Flutter plugin for my project. My plugin requires startActivityForResult but can't figure out how to use it according to Flutter plugin development. I have given my code below.
public class MyPlugin implements FlutterPlugin, MethodCallHandler {
private static final int REQUEST_CODE = 1;
Result result;
#Override
public void onAttachedToEngine(#NonNull FlutterPluginBinding flutterPluginBinding) {
channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "my_plugin");
channel.setMethodCallHandler(this);
}
#Override
public void onDetachedFromEngine(#NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}
#Override
public void onMethodCall(#NonNull MethodCall call, #NonNull Result result) {
this.result = result;
if (call.method.equals("myMethod")) {
myMethod();
} else {
result.notImplemented();
}
}
private void myMethod() {
// my intent instance will be here
startActivityForResult(intent, REQUEST_CODE); // Cannot resolve method 'startActivityForResult'
}
#Override
public boolean onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
try {
if (requestCode == REQUEST_CODE) {
result.success("done");
} else {
result.error("Something went wrong", null, null);
}
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.toString());
}
return false;
}
}
Try this solution to get the Context. After, call the intent using the Context:
private void myMethod() {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}

excuting a shel command in a spring batch listener

I am using spring batch with Java 7 to do some stuff.
When my batch finish to generate the result file i want to execute some linux command line ( coping it into a CFT server).
I added the following line of code for the listner:
#Bean
public JobExecutionListener envoieCFT() {
JobExecutionListener listener = new JobExecutionListener() {
#Override
public void beforeJob(JobExecution jobExecution) {}
#Override
public void afterJob(JobExecution jobExecution) {
final String command ="scp <file path> <user>#<ip#>:< where to copy the file>";
boolean isWindows = System.getProperty("os.name")
.toLowerCase().startsWith("windows");
Process process;
if (!isWindows) {
try {
process = Runtime.getRuntime()
.exec(String.format(command));
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("Job finished notification");
}
};
return listener ;
}
it's not working at all, did someonde ever faced the same probleme?

Screenshots is not attached Allure + Cucumber + TestNg + EventListener

Using Cucumber EventListener, I am trying to capture the screenshots in Allure report, but screenshots is not attached in the report.
Below are my CustomEventListener Code:
public class CListener extends TestRunner implements EventListener {
#Override
public void setEventPublisher(EventPublisher eventPublisher) {
eventPublisher.registerHandlerFor(TestStepFinished.class, this::stepFinished);
}
private void stepFinished(TestStepFinished event) {
PickleStepTestStep steps = (PickleStepTestStep) event.getTestStep();
String stepName = steps.getStep().getText();
if (event.getResult().getStatus().toString().equalsIgnoreCase("PASSED")) {
takeScreenshot(webDriver, event.getResult().getStatus().toString(), stepName);
} else if (event.getResult().getStatus().toString().equalsIgnoreCase("FAILED")) {
takeScreenshot(webDriver, event.getResult().getStatus().toString(), stepName);
}
Allure.addAttachment(stepName, new ByteArrayInputStream(((TakesScreenshot) webDriver).getScreenshotAs(OutputType.BYTES)));
}
private void takeScreenshot(WebDriver driver, String filePath, String screenName) {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File("Screenshots\\" + filePath + "\\" + screenName + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Runner Class:
#CucumberOptions(
features = {"classpath:Login.feature"},
plugin = {
"summary",
"pretty",
"io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm","utilities.CListener"},
glue = {"steps"}
)
public class TestRunner extends AbstractTestNGCucumberTests {
public static WebDriver webDriver;
#BeforeSuite
public void setup() {
WebDriverManager.chromedriver().setup();
webDriver = new ChromeDriver();
webDriver.manage().window().maximize();
}
#AfterSuite
public void tearDown() {
if (webDriver != null) {
webDriver.quit();
System.out.println("hello: inside teardown");
}
}
}
Sample code implementation can be found here

Deezer android sdk UI freeze during login

I implemented the Deeezer android SDK in my application and I got a user who can't log into its Deezer account on its Motorola Razr I. The login UI freezes on this page and the application restarts. He doesn't encounter the issue on its other devices.
The SDK version I use is 0.9.3
Here is a screenshot of the page where the application freezes.
What kind of information would help identify the issue?
Edit
Here is the source code :
public class LoginActivity extends Activity
{
protected static final String[] PERMISSIONS = new String[] {"basic_access", "manage_library", "delete_library", "listening_history", "manage_community"};
// DeezerConnect object
private DeezerConnect m_deezerConnect;
// Handle connection callbacks.
private DialogHandler m_dialogHandler = new DialogHandler();
// if the authentication failed, retry once
private boolean m_firstTry = true;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
m_deezerConnect = new DeezerConnectImpl(getString(R.string.deezer_app_id));
SessionStore sessionStore = new SessionStore();
AlertDialog.Builder deezerAuthDialog = new AlertDialog.Builder(this);
deezerAuthDialog.setTitle(R.string.deezer_authentication);
deezerAuthDialog.setMessage(R.string.enter_deezer_credentials);
deezerAuthDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
connectToDeezer(m_dialogHandler);
}
});
deezerAuthDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
finish();
}
});
deezerAuthDialog.setOnCancelListener(new DialogInterface.OnCancelListener()
{
#Override
public void onCancel(DialogInterface dialog)
{
finish();
}
});
deezerAuthDialog.show();
}
#Override
public void onResume()
{
super.onResume();
}
#Override
public void onDestroy()
{
super.onDestroy();
}
/**
* Connects to Deezer web services using an injectable DialogListener listener.
* #param listener event listener that will be notified of the connection progress.
*/
private void connectToDeezer(final DialogListener listener)
{
m_deezerConnect.authorize(this, PERMISSIONS, listener);
}
/** Handle DeezerConnect callbacks. */
private class DialogHandler implements DialogListener
{
#Override
public void onComplete(final Bundle values)
{
SessionStore sessionStore = new SessionStore();
sessionStore.save(m_deezerConnect, LoginActivity.this);
LoginActivity.this.finish();
}
#Override
public void onDeezerError(final DeezerError deezerError)
{
Log.e(DeemoteGlobals.TAG, "DialogError error during login" , deezerError );
LoginActivity.this.finish();
}
#Override
public void onError(final DialogError dialogError)
{
// the api returns an error while the authentication succeed, so we force a retry once
int errorCode = dialogError.getErrorCode();
if (errorCode == -10 && m_firstTry)
{
m_firstTry = false;
connectToDeezer(m_dialogHandler);
return;
}
Log.e(DeemoteGlobals.TAG, "DialogError error during login", dialogError);
}
LoginActivity.this.finish();
}
#Override
public void onCancel()
{
LoginActivity.this.finish();
}
#Override
public void onOAuthException(OAuthException oAuthException)
{
LoginActivity.this.finish();
}
}
}