How can use java class in App42 Api cloud ?

0 votes

Hi..

I'm writed some code for my custom code service using java but in console it doesnt allowed to upload it , its said can not use java class(java.lang) !

 

the code is pretty simple it just wait until an operation finished for example calling External Api to get data and return result or using App42 Service (UserService, SessionService, etc..)

please let me know how can solve this problem or another solution for doing this job

 

example of code i using

private synchronized String getData() {
		res = "nonvalue";
		SessionService session = sp.buildSessionManager();
		
		Message message = new Message();
		message.response = "nonvalue";

		Waiter waiter = new Waiter(message);
		Thread waiterThread = new Thread(waiter, "waiterThread");
		waiterThread.start();

		Notifier notifier = new Notifier(message, sp);
		Thread notifierThread = new Thread(notifier, "notifierThread");
		notifierThread.start();
		
		return message.response;
	}
	
	private class Message{
		String response;
	}
	
	private class Waiter implements Runnable {
		
		private Message message;
		
		public Waiter(Message message) {
			this.message = message;
		}

		@Override
		public void run() {
			synchronized (message) {
				try {
					//System.out.println("waiting for the notifier at");
					message.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	
	private class Notifier implements Runnable {

		Message message;
		ServiceAPI sp;

		public Notifier(Message message, ServiceAPI sp) {
			this.message = message;
			this.sp = sp;
		}
		
		@Override
		public void run() {
			SessionService session = sp.buildSessionManager();
			session.getSession("rebaz", false, new App42CallBack() {
				
				@Override
				public void onSuccess(Object response) {
					Session session = (Session)response;  
					//System.out.println("already logged" + session.getSessionId());
					finishJob ("already logged");
				}
				
				@Override
				public void onException(Exception e) {
					// TODO Auto-generated method stub
					//System.out.println("not logged" + e.getMessage());
					finishJob( "not logged" + e.getMessage());
				}
			});
		}
		
		private void finishJob(String response) {
			synchronized (message) {
				message.response = response;
				message.notify();
			}
		}
	}

 

I Can use while loop and get the same result but i dont think it good

Thanks 

asked Feb 10, 2018 in Android by Rebaz Rauf (16 points)

1 Answer

+1 vote
 
Best answer
Hello Rebaz,

 

Thread classes and Asynchronous API's are not allowed to use inside ucstom code. Werecommend you to change the API from Asynchronous mode to Synchronous mode. Regarding the solution for thread kind of script which you want to run, we would suggest you to use scheduling of custom code which run automatically your custom code after 1 minute.

To configure the same, please visit to custom code section of AppHQ Management Console and let us know if you still face any issue.

 

Regards,
Himanshu  Sharma
answered Feb 13, 2018 by hs00105 (2,005 points)
selected Feb 13, 2018 by Rebaz Rauf
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...