In a hybrid DES-ABM model I've been building in Anylogic 8, I'm struggling with sending messages. In main, there are several clinics, and within these clinics the process modeling library is used to model within clinic processes. Once the patient-agent reaches a 'seize' block, a doctor-agent is seized.
Now, what I am trying to do is, once that doctor-agent is seized, a message needs to be sent from that 'seize' block to the doctor-agent that lives in the clinic.
I've consulted the Anylogic Help manual, and I have inserted these code snippets at the 'seize' block, in the 'On entry' field:-
agent.send("Start", Clinic.doctor)
send("Start", Clinic.doctor)
Error: Description: Cannot make a static reference to the non-static field
agent.send("Start", doctor)
send("Start", doctor)
Error: Description: The method send(Object, Agent) in the type Agent is not applicable for the arguments (String, Clinic._doctor_Population).
How would I do this?
You need to send the message in the "onSeize" code section of the seize block. There, type:
send("Start", unit)
The keyword "unit" will send it to the doctor that has been seized. Read more about those keywords and where to find them here:
http://www.benjamin-schumann.com/blog/2016/2/4/the-magic-lightbulb-and-how-it-can-help-your-anylogic-modelling
Related
So I am trying out a simple full stack project of my own that involves a java backend implementation of a REST API, for which I am using the org.restlet.com framework/package and jetty as the server.
Whilst I was testing my API using Postman I noticed something wierd: Every time I started the server only the first POST/PUT/DELETE HTTP Request would get an answer, while the next ones would not receive one and on the console this error message would appear:
/* Timestamp-not-important */ org.restlet.engine.adapter.ServerAdapter commit
INFO: The connection was broken. It was probably closed by the client.
Reason: Closed
The GET HTTP Requests however do not share that problem.
I said "Fair enough, probably it's postman's fault".. after all the request made it to the server and their effects were applied. However, now that I am building the front-end this problem blocks the server's response: instead of a JSON object I get an undefined (edit: actually I get 204 No Content) on the front-end and the same "INFO" on the back-end for every POST/PUT/DELETE after the first one.
I have no idea what it is or what I am doing wrong. It has to be the backend's problem, right? But what should I look for?
Nevermind, it was the stupidest thing ever. I tried to be "smart" about returning the same Representation object (with only a 'success' JSON field) on multiple occasions by making one instance on a static final field of a class. Turns out a new instance must be returned each time.
I am using the Google Sample project to setup push notification on my app-engine backend. The following method is throwing an exception
private static void enqueuePushAlertToDevices(String alertMessage, String devicesAsJson) {
Queue notificationQueue = QueueFactory.getQueue("notification-delivery");
notificationQueue.add(TaskOptions.Builder.withMethod(TaskOptions.Method.PULL)
.param("alert", alertMessage)
.param("devices", devicesAsJson));
}
And the exception is
com.google.api.server.spi.SystemService invokeServiceMethod: The specified queue is unknown : notification-delivery
java.lang.IllegalStateException: The specified queue is unknown : notification-delivery
at com.google.appengine.api.taskqueue.QueueApiHelper.translateError(QueueApiHelper.java:104)
at com.google.appengine.api.taskqueue.QueueImpl$2.wrap(QueueImpl.java:552)
at com.google.appengine.api.taskqueue.QueueImpl$2.wrap(QueueImpl.java:521)
at com.google.appengine.api.utils.FutureWrapper.wrapAndCache(FutureWrapper.java:55)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:92)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.taskqueue.QueueApiHelper.getInternal(QueueApiHelper.java:72)
at com.google.appengine.api.taskqueue.QueueImpl.add(QueueImpl.java:413)
....
Given that the project has been around, I imagine a number of developers have been using it. So where should I define the queue "notification-delivery"? I understand the problem: I am using a queue that is not yet defined. But it's not clear to me where I should define it. I haven't found an answer in the sample code as yet. Thanks.
You didn't look hard enough :). Actually it's not obvious. Just copy the queue.xml from the sample into your project. The path in the sample is
/Downloads/solutions-ios-push-notification-sample-backend-java-master/war/WEB-INF
By all means I know the following is not possible, but it is occurring in one of our production environments:
SETUP
ESAPI 2.01
Main servlet filter setting and removing a current request thread local object:
try {
ESAPI.httpUtilities().setCurrentHTTP(request, response);
// filter logic ...
} catch (Exception e) {
LOG.error(Logger.SECURITY_FAILURE, "Error in ESAPI "
+ "security filter: " + e.getMessage(), e);
request.setAttribute("message", e.getMessage());
} finally {
ESAPI.clearCurrent();
}
all requests pass through this filter, and ESAPI.currentRequest() is used throughout the system.
Path A (http://server/path_a/)
goes through until it reaches method_a, this method is not accessible from path_b
Path B (http://server/path_b)
goes through until it reaches method_b, not accessible from path_a
Both of these paths go through the servlet filter (mapping "/*")
One of our error mails that I received suggests that path_a is throwing an error, which in turn initiates the error mail, in the mail code, the current request (via ESAPI.currentRequest()) is enumerated for request info.
PROBLEM
In the error mail, request info from path_a correlates with stacktrace info from method_b, to me this seems impossible as both run in separate threads.
QUESTION
How is this possible? I cannot re-create this locally, are their certain precautions I have to take other than setting and clearing the ThreadLocal? Can this be a problem with tomcat setup? I'm lost.
PS: code from the question has been simplified as the code base is to large for an example
Reading ESAPI code https://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/reference/DefaultHTTPUtilities.java there are some questionable practices regarding thread local.
The biggest problem I'd say is it uses InheritableThreadLocal. If thread A spawns a thread B, B will inherit A's thread local value; however, when A then clears the thread local, it doesn't affect B, so B's inherited value will stay. ESAPI probably shouldn't use InheritableThreadLocal.
I can't say how this may produce the problem you see, without knowing more about threads in your app.
I'm trying to start a Amazon EC2 cloud machine with [startInstance][2] method using aws-sdk in Java. My code is as follows.
public String startInstance(String instanceId) throws Exception {
List<String> instanceIds = new ArrayList<String>();
instanceIds.add(instanceId);
StartInstancesRequest startRequest = new StartInstancesRequest(
instanceIds);
startRequest.setRequestCredentials(getCredentials());
StartInstancesResult startResult = ec2.startInstances(startRequest);
List<InstanceStateChange> stateChangeList = startResult
.getStartingInstances();
log.trace("Starting instance '{}':", instanceId);
// Wait for the instance to be started
return waitForTransitionCompletion(stateChangeList, "running",
instanceId);
}
When I run the above code, i'm getting the following AWS error:
Status Code: 400, AWS Request ID: e1bd4795-a609-44d1-9e80-43611e80006b, AWS Erro
r Code: InvalidInstanceID.NotFound, AWS Error Message: The instance ID 'i-2b97ac
2f' does not exist
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpCli
ent.java:538)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.ja
va:283)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:168
)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.jav
a:5208)
at com.amazonaws.services.ec2.AmazonEC2Client.startInstances(AmazonEC2Cl
ient.java:2426)
AWS Error Message: The instance ID 'i-2b97ac2f' does not exist
You'll have to take the AWS response for granted here, i.e. the instance does not exist ;)
But seriously: Presumably you have already verified that you are actually running an instance with this ID in your account? Then this is most likely caused by targeting the wrong API endpoint, insofar an instance ID is only valid within a specific region (if not specified, the region defaults to 'us-east-1', see below).
In this case you need to specify the actual instance region via the setEndpoint() method of the AmazonEC2Client object within the apparently global ec2 variable before calling startInstances().
There are some examples regarding Using Regions with the AWS SDKs and all currently available AWS regional endpoint URLs are listed in Regions and Endpoints, specifically the Amazon Elastic Compute Cloud (EC2) defaults to 'us-east-1':
If you just specify the general endpoint (ec2.amazonaws.com), Amazon
EC2 directs your request to the us-east-1 endpoint.
We run a service (Qubole) that frequently spawns and then tags (and in some cases terminates) AWS instances immediately.
We have found that Amazon will, every once in a while, claim an instanceid as invalid - even though it has just created it. Retrying a few times with some sleep time thrown in usually solves the problem. Even a total retry interval of 15s proved insufficient in rare cases.
This experience comes from the useast region. We do not make api calls to different regions - so that is not an explanation. More likely - this is the infamous eventual consistency at work - where AWS is unable to provide read-after-write consistency for these api calls.
I am using the AWS ruby api and I noticed the same issue when creating an AMI image and its status is pending when I look in the AWS console but after a while the image is available for use.
Here is my script
image = ec2.images.create(:name => image_name, :instance_id => ami_id, :description => desc)
sleep 5 while image.state != :available
I sleep for about 5 sec for image to be in available but I get the error saying that the "AWS Error Message: InvalidInstanceID.NotFound". During my testing this is fine but most of the time this seems to be failing during continuous integration builds.
InvalidInstanceID.NotFound means the specified instance does not exist.
Ensure that you have indicated the region in which the instance is located, if it's not in the default region.
This error may occur because the ID of a recently created instance has not propagated through the system. For more information, see Eventual Consistency.
We are having a BAPI that uploads the specified document to SAP.
The BAPI accept three parameters:
ID, FILE_LOC and FOLDER_NAME.
And I'm setting the values as follows in the JCo code:
JCO.ParameterList paramList = function.getImportParameterList();
paramList.setValue("101XS1", "EXTERNAL_ID");
paramList.setValue("tmp", "FOLDER_NAME");
paramList.setValue("D:/upload/foo.txt", "FILE_LOCATION");
But when I'm trying to execute the BAPI, am getting the following exception:
com.sap.mw.jco.JCO$Exception: (104) RFC_ERROR_SYSTEM_FAILURE: Exception condition "NOT_SUPPORTED_BY_GUI" raised.
at com.sap.mw.jco.rfc.MiddlewareRFC$Client.nativeExecute(Native Method)
at com.sap.mw.jco.rfc.MiddlewareRFC$Client.execute(MiddlewareRFC.java:1242)
at com.sap.mw.jco.JCO$Client.execute(JCO.java:3816)
at com.sap.mw.jco.JCO$Client.execute(JCO.java:3261)
The same BAPI is working fine if I execute through thick client(SAP Logon). But through JCo, its giving this error.
This error in itself does not tell you more than "the ABAP program (function module) raised an exception named NOT_SUPPORTED_BY_GUI". What this really means is probably that the function module tried to access some GUI-related function - which is illegal for BAPIs, so either this is a custom-made RFC function module or you have found a programming error in the SAP standard coding and should open a SAPnet support ticket.
You can't use GUI services in non-gui operations, as RFC or background JOBs. In general avoid use of class cl_gui_frontend_services and functions GUI_*. Alternatively use OPEN_DATASET FOR INPUT/OUTPUT isntruction in your RFC enabled function.
Regards