onNext is not getting called on just operator - eclipse

I am using rxjava in eclipse. I cretaed the below posted example.
the issue is,, when i run the code, I receive only
onSubscribe: 0
and I dont receive any output from onNext.
please let me know why I do not receive any output from onNext, and how to fix it
code:
public static void main(String[] args) {
Observable<String> stringObservable = Observable.just("Hello from just Operator1");
stringObservable
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(new Observer<Object>() {
#Override
public void onComplete() {
// TODO Auto-generated method stub
System.out.println("onComplete: OK");
}
#Override
public void onError(Throwable arg0) {
// TODO Auto-generated method stub
}
#Override
public void onNext(Object arg0) {
// TODO Auto-generated method stub
System.out.println("onNext: " + (String) arg0);
}
#Override
public void onSubscribe(Disposable arg0) {
// TODO Auto-generated method stub
System.out.println("onSubscribe: " + arg0);
}
});
}

Related

Unable to subscribe to topic in KURA

I am writing sample Kura application in Java. But i am not able to receive message on subscribing to the topic .
In Kura web-UI:
LWT.topic attribute is :
$EDC/#account-name/#client-id (Eg: acc-name = "acc" client-id="client1")
I am publishing from client using topic
$EDC/acc/client1
But i am not receiving the message from the topic i.e following methods will never called
onControlMessageArrived() onMessageArrived()
But only there is a message on Kura.log as message arrived on topic $EDC/acc/client1 but not entering into methods onControlMessageArrived() onMessageArrived()
Code snippet:
public class ConfigurableExample implements ConfigurableComponent, CloudClientListener {
private static final Logger s_logger = LoggerFactory.getLogger(ConfigurableExample.class);
private static final String APP_ID = "Sample";
private CloudService m_cloudService;
private CloudClient m_cloudClient;
public void setCloudService(CloudService cloudService) {
s_logger.info("============================setCloudService============================{}" , cloudService!=null);
m_cloudService = cloudService;
}
public void unsetCloudService(CloudService cloudService) {
m_cloudService = null;
}
protected void activate(ComponentContext componentContext) {
s_logger.info("======================activate()===========================");
try {
if(m_cloudService==null)
throw new KuraException(KuraErrorCode.CONFIGURATION_ATTRIBUTE_INVALID);
if(m_cloudClient==null) {
m_cloudClient = m_cloudService.newCloudClient(APP_ID);
m_cloudClient.addCloudClientListener(this);
s_logger.info("===================={}================",m_cloudService.isConnected());
}
}
catch (KuraException e) {
s_logger.info("============================Exception============================ {}" , e.getMessage());
}
}
protected void deactivate(ComponentContext componentContext) {
s_logger.info("Bundle " + APP_ID + " has stopped!");
}
#Override
public void onConnectionEstablished() {
}
#Override
public void onConnectionLost() {
}
#Override
public void onControlMessageArrived(String arg0, String arg1, KuraPayload arg2, int arg3, boolean arg4) {
s_logger.info("++++++++++++++++++++++onControlMessageArrived with Parameters {},{},{},{},{} ++++++++++++++++++++",arg0, arg1,new String(arg2.getBody()),arg3,arg4);
}
#Override
public void onMessageArrived(String arg0, String arg1, KuraPayload arg2, int arg3, boolean arg4) {
s_logger.info("++++++++++++++++++++++onMessageArrived with Parameters {},{},{},{},{} ++++++++++++++++++++",arg0, arg1,new String(arg2.getBody()),arg3,arg4);
}
#Override
public void onMessageConfirmed(int arg0, String arg1) {
// TODO Auto-generated method stub
}
#Override
public void onMessagePublished(int arg0, String arg1) {
// TODO Auto-generated method stub
}
}

How to edit the tree viewer element based on context menu selection

I want to edit the tree viewer element based on my context menu option. Basically i need to update the element value which is displayed. If i double click on tree viewer element i was able to update the value, but through context menu also i should be able to do.
Sample code for adding the context menu:
protected def void createContextMenu(Viewer viewer) {
val MenuManager contextMenu = new MenuManager("Menu"); // $NON-NLS-1$
contextMenu.setRemoveAllWhenShown(true);
contextMenu.addMenuListener(new IMenuListener() {
public override void menuAboutToShow(IMenuManager mgr) {
fillContextMenu(mgr);
}
});
val Menu menu = contextMenu.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
}
/**
* Fill dynamic context menu
*
* #param contextMenu
*/
protected def void fillContextMenu(IMenuManager contextMenu) {
contextMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
contextMenu.add(new Action("Rename") {
public override void run() {
val selectedElement = (treeViewer.selection as IStructuredSelection).firstElement
}
});
}
See if this helps or let me know otherwise
package myFolder;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
public class trying {
public static void main(String[] args){
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(300,300);
TreeViewer viewer = new TreeViewer(shell);
viewer.getTree().setHeaderVisible(true);
viewer.getTree().setLinesVisible(true);
viewer.setContentProvider(new ITreeContentProvider () {
#Override
public void dispose() {
// TODO Auto-generated method stub
}
#Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// TODO Auto-generated method stub
}
#Override
public Object[] getChildren(Object arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public Object[] getElements(Object arg0) {
// TODO Auto-generated method stub
return new String[]{"Hoshe","Irani"};
}
#Override
public Object getParent(Object arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public boolean hasChildren(Object arg0) {
// TODO Auto-generated method stub
return false;
}
});
viewer.setLabelProvider(new ILabelProvider(){
#Override
public void addListener(ILabelProviderListener arg0) {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
// TODO Auto-generated method stub
}
#Override
public boolean isLabelProperty(Object arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
#Override
public void removeListener(ILabelProviderListener arg0) {
// TODO Auto-generated method stub
}
#Override
public Image getImage(Object arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public String getText(Object arg0) {
// TODO Auto-generated method stub
return "hoshe";
}
});
viewer.setInput("Hoshe");
Menu popupMenu = new Menu(viewer.getControl());
MenuItem newItem = new MenuItem(popupMenu, SWT.CHECK);
newItem.setText("New");
MenuItem refreshItem = new MenuItem(popupMenu, SWT.CHECK);
refreshItem.setText("Refresh");
MenuItem deleteItem = new MenuItem(popupMenu, SWT.CHECK);
deleteItem.setText("Delete");
popupMenu.addMenuListener(new MenuListener() {
#Override
public void menuShown(MenuEvent arg0) {
// TODO Auto-generated method stub
}
#Override
public void menuHidden(MenuEvent arg0) {
// TODO Auto-generated method stub
display.asyncExec(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
TreeItem [] arr = viewer.getTree().getSelection();
for(MenuItem item2 : popupMenu.getItems()){
boolean bool1 = item2.getSelection();
if(bool1){
arr[0].setText(item2.getText());
item2.setSelection(false);
}
}
}
});
}
});
viewer.getTree().setMenu(popupMenu);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

Click handler of button

I want to add a button and add click handler to it after entering the values in database.
I want that button to be on onSucess of greeting service.
help me
public static void edit1(String fnme,String lnme,String clgn,String scn){
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>()
{
public void onSuccess(String result)
{
Window.alert("successfully entered");
// TODO Auto-generated method stub
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler);
}
public void onFailure(Throwable caught)
{
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler
{
public void onClick(ClickEvent e)
{
//create();
}
}
but this is not working.
Do you need the click handler?
Anyway this is what I think you're trying to do:
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler);
public static void edit1(String fnme,String lnme,String clgn,String scn)
{
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>()
{
public void onSuccess(String result)
{
Window.alert("successfully entered");
// TODO Auto-generated method stub
create();
}
public void onFailure(Throwable caught)
{
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler
{
public void onClick(ClickEvent e)
{
// create();
}
}
Your MyClickHandler does nothing inside the onClick() method. It should work as long as you put code. Try this:
public static void edit1(String fnme,String lnme,String clgn,String scn){
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>() {
public void onSuccess(String result) {
Window.alert("successfully entered");
// TODO Auto-generated method stub
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler() {
public void onClick(ClickEvent e) {
//DO SOMETHING HERE
}
});
}
public void onFailure(Throwable caught) {
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler {
public void onClick(ClickEvent e) {
/* OR DO SOMETHING HERE, BUT THAT WILL AFFECT ALL
* INSTANCES OF MyClickHandler
*/
}
}

Adding a Camera to my Android App and Initializing it on application start up

I'm pretty new to programming but here is a code I have. I'm trying to develop an app and I want it to open the camera feature right away. This is what I'm working with. It's asking me to add more details so I figure I should type more... Any help would be appreciated. This is my only grade for a class that is taught very poorly
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder sHolder;
public Camera camera= null;{
}
public CameraSurfaceView(Context context) {
super(context);
sHolder= getHolder();
sHolder .addCallback(this);
// TODO Auto-generated constructor stub
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
Camera.Parameters params= camera.getParameters();
params.setPreviewSize(width, height);
camera.setParameters(params);
camera.startPreview();
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try{
camera.setPreviewDisplay(sHolder);
}catch(Exception e){
}
// TODO Auto-generated method stub
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera= null;
}
public void capture (Camera.PictureCallback jpegHandler){
camera.takePicture(null, null, jpegHandler);
}
}

GWT RPC mechanism how to use non void return type

I have a scenario wherein I need to specify a return type to the Synchrnous function, the code is as follows :
#RemoteServiceRelativePath("show_box")
public interface ShowBoxCommandService extends RemoteService{
public ArrayList<String> showBox();
}
The implementation of the method on the server is :
public ArrayList<String> showBox() {
ArrayList<String> box = new ArrayList<String>();
Iterator<Box> boxes = BoxRegistry.getInstance().getBoxes();
while (boxes.hasNext()) {
box.add(boxes.next().toString());
}
return box;
}
I am trying to define the callback variable in the following format at the client side in order to call the method
AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
update with the aync interface code :
public interface ShowBoxCommandServiceAsync {
void showBox(AsyncCallback<ArrayList<String>> callback);
}
But this is causing the definition of the method in the Async method to change.
Any ideas or clues will be helpful.
Thanks,
Bhavya
P.S. Apologies if this is a repetition
The callback should be:
AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(ArrayList<String> result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
If you don't need to utilize the result then you can ignore it, but if that is the case, you should probably question your design and why you would need the method to return an ArrayList<String> in the first place.
If the service interface looks like this:
public interface ShowBoxCommandService extends RemoteService {
public ArrayList<String> showBox();
}
then you must have an associated async interface:
public interface ShowBoxCommandServiceAsync {
public void showBox(AsyncCallback<ArrayList<String>> callback);
}
Which means, that the type of the callback that you should pass to showBox is AsyncCallback<ArrayList<String>>.
new AsyncCallback<ArrayList<String>>() {
#Override
public void onSuccess(ArrayList<String> list) {
// ...
}
#Override
public void onFailure(Throwable caught) {
// ...
}
}
Your callback should not be Void. If your synchronous method returns a List of Strings, the async callback method should receive the List. You'll have to use the ArrayList, because the class needs to implement the Serializable interface.
AsyncCallback<ArrayList<String>> callback = new AsyncCallback<ArrayList<String>>() {
public void onFailure(Throwable caught) {
// TODO: Do something with errors.
// console was not started properly
}
#Override
public void onSuccess(ArrayList<String> result) {
// TODO Auto-generated method stub
// dialog saying that the console is started succesfully
}
};
Huh? Your method returns an ArrayList and you are declaring void in your call?
Change <Void> to <ArrayList<String>>