0

CellTable を持つ Web ページを作成しています。このテーブルに hbase テーブルのデータを入力する必要があります。

hbase テーブルからデータを取得するメソッドを作成し、テストしました。

しかし、そのメソッドを GWT 非同期 RPC メソッドとして呼び出すと、rpc 呼び出しは成功しますが、何も返されません。私の場合、空のリストが返されます。アラート ボックスには、リストのサイズが 0 として表示されます。

以下は関連するコードです。

助けてください。

greetingService.getDeviceIDData(new AsyncCallback<List<DeviceDriverBean>>(){
                    public void onFailure(Throwable caught) {
                        // Show the RPC error message to the user
                        System.out.println("RPC Call failed");
                        Window.alert("Data : RPC call failed");

                    }

                    public void onSuccess(List<DeviceDriverBean> result) {                      
                        //on success do something
                        Window.alert("Data : RPC call successful");
                        //deviceDataList.addAll(result);                    
                        Window.alert("Result size: " +result.size());                       


                        // Add a text column to show the driver name.
                        TextColumn<DeviceDriverBean> nameColumn = new TextColumn<DeviceDriverBean>() {
                            @Override
                            public String getValue(DeviceDriverBean object) {
                                Window.alert(object.getName());
                                return object.getName();

                            }
                        };
                        table.addColumn(nameColumn, "Name");

                        // Add a text column to show the device id      
                        TextColumn<DeviceDriverBean> deviceidColumn = new TextColumn<DeviceDriverBean>() {
                            @Override
                            public String getValue(DeviceDriverBean object) {
                                return object.getDeviceId();
                            }
                        };
                        table.addColumn(deviceidColumn, "Device ID");
                        table.setRowCount(result.size(), true);

// more code here to add columns in celltable
                        // Push the data into the widget.
                        table.setRowData(0, result);
                        SimplePager pager = new SimplePager();
                        pager.setDisplay(table);
                        VerticalPanel vp = new VerticalPanel();
                        vp.add(table);
                        vp.add(pager);      

                        // Add it to the root panel.
                        RootPanel.get("datagridContainer").add(vp);
                    }                   
                }); 

hbase からデータを取得するコード (サーバー側コード)

public List<DeviceDriverBean> getDeviceIDData()
            throws IllegalArgumentException {

        List<DeviceDriverBean> deviceidList = new ArrayList<DeviceDriverBean>();

        // Escape data from the client to avoid cross-site script
        // vulnerabilities.
        /*
         * input = escapeHtml(input); userAgent = escapeHtml(userAgent);
         * 
         * return "Hello, " + input + "!<br><br>I am running " + serverInfo +
         * ".<br><br>It looks like you are using:<br>" + userAgent;
         */

        try {
            Configuration config = HbaseConnectionSingleton.getInstance()
                    .HbaseConnect();
            HTable testTable = new HTable(config, "driver_details");
            byte[] family = Bytes.toBytes("details");
            Scan scan = new Scan();
            int cnt = 0;
            ResultScanner rs = testTable.getScanner(scan);
            for (Result r = rs.next(); r != null; r = rs.next()) {

                DeviceDriverBean deviceDriverBean = new DeviceDriverBean();
                byte[] rowid = r.getRow(); // Category, Date, Sentiment
                NavigableMap<byte[], byte[]> map = r.getFamilyMap(family);
                Iterator<Entry<byte[], byte[]>> itrt = map.entrySet()
                        .iterator();

                deviceDriverBean.setDeviceId(Bytes.toString(rowid));

                while (itrt.hasNext()) {

                    Entry<byte[], byte[]> entry = itrt.next();
                    //cnt++;
                    //System.out.println("Count : " + cnt);

                    byte[] qual = entry.getKey();
                    byte[] val = entry.getValue();

                    if (Bytes.toString(qual).equalsIgnoreCase("account_number")) {
                        deviceDriverBean.setAccountNo(Bytes.toString(val));
                    } else if (Bytes.toString(qual).equalsIgnoreCase("make")) {
                        deviceDriverBean.setMake(Bytes.toString(val));
                    } else if (Bytes.toString(qual).equalsIgnoreCase("model")) {
                        deviceDriverBean.setModel(Bytes.toString(val));
                    } else if (Bytes.toString(qual).equalsIgnoreCase("driver_name")) {
                        deviceDriverBean.setName(Bytes.toString(val));
                    } else if (Bytes.toString(qual).equalsIgnoreCase("premium")) {
                        deviceDriverBean.setPremium(Bytes.toString(val));
                    } else if (Bytes.toString(qual).equalsIgnoreCase("year")) {
                        deviceDriverBean.setYear(Bytes.toString(val));
                    } else {
                        System.out.println("No match found");
                    }
                    /*
                     * System.out.println(Bytes.toString(rowid) + " " +
                     * Bytes.toString(qual) + " " + Bytes.toString(val));
                     */
                }

                deviceidList.add(deviceDriverBean);
            }
        }

        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        catch (Exception e) {
            // System.out.println("Message: "+e.getMessage());
            e.printStackTrace();
        }

        return deviceidList;

    }
4

2 に答える 2

0

これは、hbase によるサーバー側での遅延フェッチでしょうか。これは、リストを返す場合、hbase が実際にリストを読み取るためのトリガーを取得せず、単純に空のリストを取得することを意味します。過去にGAEで同様の問題を見たことがあります。これは、リストをクライアントに返す直前にリストのサイズを尋ねるだけで解決できます。

于 2013-07-25T20:26:44.253 に答える