I'm having issues with doing proper save in hibernate/entity manager in swing desktop application. I have a method that counts proper logouts from application via call to webservice. Webservice method looks like this:
public void setLoggodOutCount(User user){
user.setLoggedOutCount(12);
em.merge(user);
}
After calling this webservice method my program exits. Then when I look at my server logs I can see that there was two updates executed. One with good value=12 and one with prev value=11. Sometimes there are in good order, sometimes not. What can I do to force my update being executed last?
Related
I'm working with python scripts in Inductive Automation's Ignition HMI (java backend) software. I'm trying to write a script that locates other scripts that are tied to certain objects. Currently I have
result = window.getRootContainer().getComponent("Group 1").getComponent("TheObject").mouseClicked
which gets the window displaying my object, enters the root container of that object, then the group that the object is in and then finally the script tied to the mouseClicked event on TheObject. When I run this and print the result, I don't get an error, but:
<CompoundCallable with 0 callables>
Has anyone seen this before? Does anyone know what I may need to change in my first line of code to access the actual data stored in the mouseClicked script?
Looks like there is no code associated with the mouseClicked event of that object.
CompoundCallable is a "composition of callables", something callable that calls multiple callables - kind of a callable container. It is used to allow registering multiple functions to be called in a single event handler.
However your CompoundCallable contains zero callables. That means nothing will be called if you call it.
If I understand what you're asking, I don't believe you'll be able to access the data that is in that script (variables, etc.). You could have the mouseClicked script write data to something else in order to access data. There are multiple possibilities for that: Custom Window Property, Custom Component Property, or a tag.
so I'm pretty new to Spring and used the Spring Initializr to create a new project. I do not have any configuration .XMLs or similiar configuration files. I followed this tutorial to get things going.
My controller class basically looks like the following:
#Controller
#Configuration
#EnableScheduling
public class IndexController {
#GetMapping("/")
public String index(Model m) {
m.addAttribute("Title", "New Website");
m.addAttribute("MenuOne", InformationProvider.getMenuOneLink());
m.addAttribute("MenuTwo", InformationProvider.getMenuTwoLink());
m.addAttribute("StaffNumber", InformationProvider.getNumberOfStaff());
m.addAttribute("Birthdays", InformationProvider.getBirthdaysOfToday());
return "dashboard";
}
}
This works fine and everything is doing what it is supposed to be. Unfortunately the attributes which are getting their data by the InformationProvider class need to be updated at run time. The InformationProvider is approaching different APIs on the web and my idea either was to pull data from these APIs every 10 hours for example or to pull the data again on a site refresh.
From my understanding my method is supposed to be called each time someone would enter the URL localhost:8080/. My first idea basically was to refresh the site after 10 hours. The method is called when the site is refreshed and it is returning "dashboard" each time but the values are not updated. To update my attributes I have to restart my application. I was looking at the #scheduled annotation but this does not really help me since it is only working for methods which have void as return time and do not have object parameters. So scheduling my method index doesn't work and is probably the wrong way to go anyway.
I was googling a lot regarding this topic but I couldn't really find a solution for this specific problem where you only have a model as parameter in your controller method and want to update it afterwards.
What is the best approach for this problematic? I was checking the JavaDoc of the model class but it does not contain a remove or update method. Do I need to approach the HashMap behind the model directly and overwrite an attribute by an existing key to update it?
Edit:
To be more specific about the InformationProvider class, it is basically returning a String received by a cURL method called from Java. Nothing more.
Thanks in advance
InformationProvider class need to be updated at run time
If you tried to Schedule this exact method, its possible that due to InformationProvider class being a static class, it serves the data when it was first initialized. It's hard to tell without seeing what happens in that class. I would rather #Schedule a Service that populates this Object, or rather from a storage, where you can read the cached data.
Regarding your real problem, fetching from different sources.
#Schedule is good for running jobs, but I would avoid, unless you need to cache the data in your server. If it's possible, you can do it live, always fresh data, and easier.
In general for the problem.
I would fetch the data (cache is speed is crucial), with a service that you can Schedule, but have other controls over it for e.g. force refresh from another endpoint, do transformation on server side, and stream it to your page via the model. That should be the basic flow.
The solution for this problem was pretty simple, I just had to refresh the page for example by javascript. Might be as well be able to do this by scheduling.
I'm trying to create a game where JADE Agents are the 'enemies' and they chase a player around a maze.
So far I have:
MazeView.java (uses Swing to paint various things on the screen, and lets the user interact through button presses)
Enemy.java (a JADE agent that will have behaviours like search, pursue, etc.)
And a few other classes doing things like generating the actual maze data structure etc.
My problem is that, while I can instantiate an Agent and paint it on the screen, for some reason I can't add any behaviours. For example, if I wanted something like this (in Enemy.java):
protected void setup() {
// Add a TickerBehaviour that does things every 5 seconds
addBehaviour(new TickerBehaviour(this, 5000) {
protected void onTick() {
// This doesn't seem to be happening?
System.out.println("5 second tick... Start new patrol/do something?");
myAgent.addBehaviour(new DoThings());
}
}); // end of addBehaviour
System.out.println("End of setup()...");
} // end of setup
When I run the code, no errors are thrown, and I can see "End of setup()..." displayed in console. So for some reason it's just not going into the addBehaviour() method at all. Even if the DoThings() behaviour didn't work (right now it just prints a message), it should at least display the "5 second tick" message before throwing an error. What is going wrong here?
I think it could be something to do with the fact that currently there is no concept of 'time' in my maze. The user presses a key, and THEN processing happens. So having an agent that does things every 5 seconds might not work when there is no real way to facilitate that in the maze? But I'm still confused as to why it just skips addBehaviour() and I don't get an error.
A possible solution might be to re-implement my maze as a constant loop that waits for input. Would that allow a concept of 'time'? Basically I'm not sure how to link the two together. I am a complete beginner with JADE.
Any ideas would be appreciated. Thanks!
I've never used Jade, but my first thought was that you are adding behaviors and then assuming that Jade will decide to run them at some point. When you say that you never see your behaviors activate, it strengthened that hypothesis.
I looked at the source and sure enough, addBehaviour() and removeBehaviour() simply add and remove from a collection called myScheduler. Looking at the usages, I found a private method called activateAllBehaviours() that looked like it ran the Behaviours. That method is called from the public doWake() on the Agent class.
I would guess that you simply have to call doWake() on your Agent. This is not very apparent from the JavaDoc or the examples. The examples assume that you use the jade.Boot class and simply pass the class name of your agent to that Boot class. This results in the Agent getting added to a container that manages the "waking" and running of your Agents. Since you are running Swing for your GUI, I think that you will have to run your Agents manually, rather than the way that the examples show.
I got more curious, so I wrote my own code to create and run the Jade container. This worked for me:
Properties containerProps = new jade.util.leap.Properties();
containerProps.setProperty(Profile.AGENTS, "annoyer:myTest.MyAgent");
Profile containerProfile = new ProfileImpl(containerProps);
Runtime.instance().setCloseVM(false);
Runtime.instance().createMainContainer(containerProfile);
This automatically creates my agent of type myTest.MyAgent and starts running it. I implemented it similar to your code snippet, and I saw messages every 5 seconds.
I think you'll want to use setCloseVM(false) since your UI can handle closing down the JVM, not the Jade container.
I have a simple Web service in Java and Weblogic. In this web service, I have a method which receive some data, call another webservice, write in DB and then answer with result.
If I try it with only one call it works fine, but, if I've tried with Soap UI, creating a TestCase, where you can call the web service in multiple threads, sometimes, it works ok, but sometimes, when there are a call in the middle of another, the result is not correct.
The problem is that when I call web service method I init some variables I have to analyze and save in DB, so, if a call is interrupted, these variables are updated and when the first call finish, the result is not correct (they are with init values).
If I put synchronized in web service method it works, but I think it's not the best way to do it, because I want to allow multiple users at the same time.
What's is the best way to do this?
Thank you very much
when you start writing client specific applications, you're required to keep a data for client state in your DB.
So, when each client accesses your web server with their cookie/session, you can get the client-id (encrypted in side cookie/session) and evaluate server-side parameters based on values of client in DB.
Thank you to kolossus comment, I've solved it removing global variables and creating only local variables, so each call will create a new variable and not overwrite common variables.
I have an application that uses call activity to call people. However, when the call is made, the number will be logged to recent call list, and I don't want this to happen.
What would be the best way for the phone to not to log the calls made?
I am not sure if the recent call list uses the same database as the call log, however if it does you can just delete the call from that content provider after it is made.
Take a look at this: http://www.mobisoftinfotech.com/blog/android/androidcalllogdeletion/