使用服务器Java的Apache Thrift阵列&;Javascript客户端
im使用Javascript显示用Java生成的信息。 我说的是10000个数据,所有这些数据都是用Java生成的,并且是为了使用随机值测试Im。我想在我的javascript页面中看到这10000个值 我已经有了一个简单的服务器Java和一个客户端Javascript来共享两个副本 这是两个双人间的储蓄文件:使用服务器Java的Apache Thrift阵列&;Javascript客户端,javascript,java,apache,thrift,Javascript,Java,Apache,Thrift,im使用Javascript显示用Java生成的信息。 我说的是10000个数据,所有这些数据都是用Java生成的,并且是为了使用随机值测试Im。我想在我的javascript页面中看到这10000个值 我已经有了一个简单的服务器Java和一个客户端Javascript来共享两个副本 这是两个双人间的储蓄文件: namespace java test_thrift service test{ double number(1:double n1, 2:double n2) } publi
namespace java test_thrift
service test{
double number(1:double n1, 2:double n2)
}
public double number(double n1, double n2) throws TException {
//System.out.println(n1 + " - " + n2);
Random rnd = new Random();
n1 = rnd.nextDouble() * 10 + 1;
n2 = rnd.nextDouble() * 15 + 10;
return n2;
}
这是我的Javascript客户端的代码
function calc() {
var transport = new Thrift.Transport("/service");
var protocol = new Thrift.Protocol(transport);
var client = new testClient(protocol);
var workbench = Math.random()*1000;
try {
result = client.number(workbench);
$('#result').val(result);
$('#result').css('color', 'black');
document.getElementById("demo").innerHTML = result;
} catch(ouch){
$('#result').val(ouch.why);
$('#result').css('color', 'red');
}
}
我发送随机消息只是为了得到返回的范围。示例:1返回3到9之间的值,2返回9到15之间的值,以此类推
在java中,我有一个testHandler类:
namespace java test_thrift
service test{
double number(1:double n1, 2:double n2)
}
public double number(double n1, double n2) throws TException {
//System.out.println(n1 + " - " + n2);
Random rnd = new Random();
n1 = rnd.nextDouble() * 10 + 1;
n2 = rnd.nextDouble() * 15 + 10;
return n2;
}
这返回1个值。我希望看到我的Javascript页面中的所有内容。但是有10000个元素。我该怎么做
我还想补充一点,要共享的最终结构如下:
dis[10000][3]={
ABC,12.5,13.5,
ACD,14.4,11.5,
.....ETC......}
for (var i = result.length - 1; i >= 0; i--) {
//div.innerHTML = div.innerHTML + '\n' + result[i];
div.insertAdjacentHTML('beforeend', '\n'+result[i].did+' '+result[i].l_x+' '+result[i].l_y+' '+result[i].l_z+' '+result[i].m_x+' '+result[i].m_y+' '+result[i].m_z+' '+result[i].a_x+' '+result[i].a_y+' '+result[i].a_z+' '+result[i].g_x+' '+result[i].g_y+' '+result[i].g_z+' '+result[i].d_t+' '+result[i].tp+' '+result[i].r_q+' '+result[i].o_m+' '+result[i].b_v);
};
}
public class TestHandler implements test.Iface {
public Random rnd = new Random();
public static List<Cell> p = new ArrayList<Cell>();
public void test() {
for (int i = 0; i < 10000; i++) {
Cell a = new Cell();
a.did = "SomeString";
a.l_x = rnd.nextDouble()*10+1;
a.l_y = rnd.nextDouble()*10+1;
a.l_z = 0.0;
a.m_x = 0.0;
a.m_y = 0.0;
a.m_z = 0.0;
a.a_x = 0.0;
a.a_y = 0.0;
a.a_z = 0.0;
a.g_x = 0.0;
a.g_y = 0.0;
a.g_z = 0.0;
a.d_t = "String here";
a.tp = 0.0;
a.r_q = 0.0;
a.o_m = "A";
a.b_v = 0.0;
p.add(a);
}
}
@Override
public List<Cell> number(short req) throws TException {
test();
return ips.ReminderBeep.list_d;
}
我卡住了
找到了这个,但我不知道如何让它工作:/
namespace java test_thrift
typedef list<double> Vector
struct test
{
1:i32 rows,
2:i32 cols,
3:list<Vector> data,
}
名称空间java测试\u节俭
typedef列表向量
结构测试
{
1:i32行,
2:i32 cols,
3:列表数据,
}
使用此IDL文件
namespace java test_thrift
struct MyPair {
1: double one
2: double two
}
service test{
list<double> number( 1 : list<MyPair> data)
}
名称空间java测试\u节俭
结构MyPair{
1:双1
2:双人2
}
服务测试{
列表编号(1:列表数据)
}
然后调用该函数,如下所示:
var list = [];
for( var i = 0; i < 10000; ++i) {
list.push({
one : Math.random()*1000,
two : Math.random()*1000
});
}
result = client.number(list);
var list=[];
对于(变量i=0;i<10000;++i){
list.push({
一:Math.random()*1000,
二:Math.random()*1000
});
}
结果=客户编号(列表);
结果应该是返回值的列表,当然服务器端是相应实现的。使用此IDL文件
namespace java test_thrift
struct MyPair {
1: double one
2: double two
}
service test{
list<double> number( 1 : list<MyPair> data)
}
名称空间java测试\u节俭
结构MyPair{
1:双1
2:双人2
}
服务测试{
列表编号(1:列表数据)
}
然后调用该函数,如下所示:
var list = [];
for( var i = 0; i < 10000; ++i) {
list.push({
one : Math.random()*1000,
two : Math.random()*1000
});
}
result = client.number(list);
var list=[];
对于(变量i=0;i<10000;++i){
list.push({
一:Math.random()*1000,
二:Math.random()*1000
});
}
结果=客户编号(列表);
结果应该是返回值的列表,当然服务器端是相应实现的。所以,我设法修复了它。这是一个客户端JavasCript,它可以进行重新请求,Java服务器返回10000 x 18矩阵 旧档案: 名称空间java测试节约
struct Cell {
1: string did
2: double l_x
3: double l_y
4: double l_z
5: double m_x
6: double m_y
7: double m_z
8: double a_x
9: double a_y
10: double a_z
11: double g_x
12: double g_y
13: double g_z
14: string d_t
15: double tp
16: double r_q
17: string o_m
18: double b_v
}
service test{
list<Cell> number( 1 : i16 req)
}
结果y得到[10000][18]答案,并按如下方式打印:
dis[10000][3]={
ABC,12.5,13.5,
ACD,14.4,11.5,
.....ETC......}
for (var i = result.length - 1; i >= 0; i--) {
//div.innerHTML = div.innerHTML + '\n' + result[i];
div.insertAdjacentHTML('beforeend', '\n'+result[i].did+' '+result[i].l_x+' '+result[i].l_y+' '+result[i].l_z+' '+result[i].m_x+' '+result[i].m_y+' '+result[i].m_z+' '+result[i].a_x+' '+result[i].a_y+' '+result[i].a_z+' '+result[i].g_x+' '+result[i].g_y+' '+result[i].g_z+' '+result[i].d_t+' '+result[i].tp+' '+result[i].r_q+' '+result[i].o_m+' '+result[i].b_v);
};
}
public class TestHandler implements test.Iface {
public Random rnd = new Random();
public static List<Cell> p = new ArrayList<Cell>();
public void test() {
for (int i = 0; i < 10000; i++) {
Cell a = new Cell();
a.did = "SomeString";
a.l_x = rnd.nextDouble()*10+1;
a.l_y = rnd.nextDouble()*10+1;
a.l_z = 0.0;
a.m_x = 0.0;
a.m_y = 0.0;
a.m_z = 0.0;
a.a_x = 0.0;
a.a_y = 0.0;
a.a_z = 0.0;
a.g_x = 0.0;
a.g_y = 0.0;
a.g_z = 0.0;
a.d_t = "String here";
a.tp = 0.0;
a.r_q = 0.0;
a.o_m = "A";
a.b_v = 0.0;
p.add(a);
}
}
@Override
public List<Cell> number(short req) throws TException {
test();
return ips.ReminderBeep.list_d;
}
最后,我的Java服务器中的处理程序如下所示:
dis[10000][3]={
ABC,12.5,13.5,
ACD,14.4,11.5,
.....ETC......}
for (var i = result.length - 1; i >= 0; i--) {
//div.innerHTML = div.innerHTML + '\n' + result[i];
div.insertAdjacentHTML('beforeend', '\n'+result[i].did+' '+result[i].l_x+' '+result[i].l_y+' '+result[i].l_z+' '+result[i].m_x+' '+result[i].m_y+' '+result[i].m_z+' '+result[i].a_x+' '+result[i].a_y+' '+result[i].a_z+' '+result[i].g_x+' '+result[i].g_y+' '+result[i].g_z+' '+result[i].d_t+' '+result[i].tp+' '+result[i].r_q+' '+result[i].o_m+' '+result[i].b_v);
};
}
public class TestHandler implements test.Iface {
public Random rnd = new Random();
public static List<Cell> p = new ArrayList<Cell>();
public void test() {
for (int i = 0; i < 10000; i++) {
Cell a = new Cell();
a.did = "SomeString";
a.l_x = rnd.nextDouble()*10+1;
a.l_y = rnd.nextDouble()*10+1;
a.l_z = 0.0;
a.m_x = 0.0;
a.m_y = 0.0;
a.m_z = 0.0;
a.a_x = 0.0;
a.a_y = 0.0;
a.a_z = 0.0;
a.g_x = 0.0;
a.g_y = 0.0;
a.g_z = 0.0;
a.d_t = "String here";
a.tp = 0.0;
a.r_q = 0.0;
a.o_m = "A";
a.b_v = 0.0;
p.add(a);
}
}
@Override
public List<Cell> number(short req) throws TException {
test();
return ips.ReminderBeep.list_d;
}
公共类TestHandler实现test.Iface{
公共随机rnd=新随机();
公共静态列表p=newarraylist();
公开无效测试(){
对于(int i=0;i<10000;i++){
单元a=新单元();
a、 did=“SomeString”;
a、 l_x=rnd.nextDouble()*10+1;
a、 l_y=rnd.nextDouble()*10+1;
a、 l_z=0.0;
a、 m_x=0.0;
a、 m_y=0.0;
a、 m_z=0.0;
a、 a_x=0.0;
a、 a_y=0.0;
a、 a_z=0.0;
a、 g_x=0.0;
a、 g_y=0.0;
a、 g_z=0.0;
a、 d_t=“此处字符串”;
a、 tp=0.0;
a、 r_q=0.0;
a、 o_m=“a”;
a、 b_v=0.0;
p、 添加(a);
}
}
@凌驾
公共列表编号(短请求)引发异常{
test();
返回ips.rementerbeep.list\u d;
}
我希望这对某些人有用,所以,我设法解决了它。下面是一个客户端JavasCript,可以进行重新请求,Java服务器返回10000 x 18矩阵 旧档案: 名称空间java测试节约
struct Cell {
1: string did
2: double l_x
3: double l_y
4: double l_z
5: double m_x
6: double m_y
7: double m_z
8: double a_x
9: double a_y
10: double a_z
11: double g_x
12: double g_y
13: double g_z
14: string d_t
15: double tp
16: double r_q
17: string o_m
18: double b_v
}
service test{
list<Cell> number( 1 : i16 req)
}
结果y得到[10000][18]答案,并按如下方式打印:
dis[10000][3]={
ABC,12.5,13.5,
ACD,14.4,11.5,
.....ETC......}
for (var i = result.length - 1; i >= 0; i--) {
//div.innerHTML = div.innerHTML + '\n' + result[i];
div.insertAdjacentHTML('beforeend', '\n'+result[i].did+' '+result[i].l_x+' '+result[i].l_y+' '+result[i].l_z+' '+result[i].m_x+' '+result[i].m_y+' '+result[i].m_z+' '+result[i].a_x+' '+result[i].a_y+' '+result[i].a_z+' '+result[i].g_x+' '+result[i].g_y+' '+result[i].g_z+' '+result[i].d_t+' '+result[i].tp+' '+result[i].r_q+' '+result[i].o_m+' '+result[i].b_v);
};
}
public class TestHandler implements test.Iface {
public Random rnd = new Random();
public static List<Cell> p = new ArrayList<Cell>();
public void test() {
for (int i = 0; i < 10000; i++) {
Cell a = new Cell();
a.did = "SomeString";
a.l_x = rnd.nextDouble()*10+1;
a.l_y = rnd.nextDouble()*10+1;
a.l_z = 0.0;
a.m_x = 0.0;
a.m_y = 0.0;
a.m_z = 0.0;
a.a_x = 0.0;
a.a_y = 0.0;
a.a_z = 0.0;
a.g_x = 0.0;
a.g_y = 0.0;
a.g_z = 0.0;
a.d_t = "String here";
a.tp = 0.0;
a.r_q = 0.0;
a.o_m = "A";
a.b_v = 0.0;
p.add(a);
}
}
@Override
public List<Cell> number(short req) throws TException {
test();
return ips.ReminderBeep.list_d;
}
最后,我的Java服务器中的处理程序如下所示:
dis[10000][3]={
ABC,12.5,13.5,
ACD,14.4,11.5,
.....ETC......}
for (var i = result.length - 1; i >= 0; i--) {
//div.innerHTML = div.innerHTML + '\n' + result[i];
div.insertAdjacentHTML('beforeend', '\n'+result[i].did+' '+result[i].l_x+' '+result[i].l_y+' '+result[i].l_z+' '+result[i].m_x+' '+result[i].m_y+' '+result[i].m_z+' '+result[i].a_x+' '+result[i].a_y+' '+result[i].a_z+' '+result[i].g_x+' '+result[i].g_y+' '+result[i].g_z+' '+result[i].d_t+' '+result[i].tp+' '+result[i].r_q+' '+result[i].o_m+' '+result[i].b_v);
};
}
public class TestHandler implements test.Iface {
public Random rnd = new Random();
public static List<Cell> p = new ArrayList<Cell>();
public void test() {
for (int i = 0; i < 10000; i++) {
Cell a = new Cell();
a.did = "SomeString";
a.l_x = rnd.nextDouble()*10+1;
a.l_y = rnd.nextDouble()*10+1;
a.l_z = 0.0;
a.m_x = 0.0;
a.m_y = 0.0;
a.m_z = 0.0;
a.a_x = 0.0;
a.a_y = 0.0;
a.a_z = 0.0;
a.g_x = 0.0;
a.g_y = 0.0;
a.g_z = 0.0;
a.d_t = "String here";
a.tp = 0.0;
a.r_q = 0.0;
a.o_m = "A";
a.b_v = 0.0;
p.add(a);
}
}
@Override
public List<Cell> number(short req) throws TException {
test();
return ips.ReminderBeep.list_d;
}
公共类TestHandler实现test.Iface{
公共随机rnd=新随机();
公共静态列表p=newarraylist();
公开无效测试(){
对于(int i=0;i<10000;i++){
单元a=新单元();
a、 did=“SomeString”;
a、 l_x=rnd.nextDouble()*10+1;
a、 l_y=rnd.nextDouble()*10+1;
a、 l_z=0.0;
a、 m_x=0.0;
a、 m_y=0.0;
a、 m_z=0.0;
a、 a_x=0.0;
a、 a_y=0.0;
a、 a_z=0.0;
a、 g_x=0.0;
a、 g_y=0.0;
a、 g_z=0.0;
a、 d_t=“此处字符串”;
a、 tp=0.0;
a、 r_q=0.0;
a、 o_m=“a”;
a、 b_v=0.0;
p、 添加(a);
}
}
@凌驾
公共列表编号(短请求)引发异常{
test();
返回ips.rementerbeep.list\u d;
}
我希望这对某些人有用,因为我正确理解了这个问题:使用
列表
和对
作为结构对{1:double one,2:double two}
?通过这种方式,您可以通过一次呼叫传递任意多的数据。如果更改服务器IDL不是一个有效的选择,那么您必须执行10000次呼叫(这将降低性能)。确切地说,我只想进行一次呼叫并传递所有信息。但我不知道如何“列出”有效。我从未使用过。你知道一些例子吗?假设我正确理解这个问题:使用list
和pair
作为struct pair{1:double one,2:double two}
?通过这种方式,您可以通过一次呼叫传递任意多的数据。如果更改服务器IDL不是一个有效的选择,那么您必须执行10000次呼叫(这将降低性能)。确切地说,我只想进行一次呼叫并传递所有信息。但我不知道如何“列出”有用。我从来没有使用过。你知道一些例子吗?如果我重用服务器并只更改处理程序就可以了?我试图只打印列表的大小,但我做不到。Javascript的文件总是会被捕获。很抱歉这么烦人,我是个新手,但非常感谢你的帮助。如果我重用服务器并只更改处理程序就可以了?我知道试图打印列表的大小,但我做不到。Javascript的文件总是很重要。很抱歉这么烦人,我是一个节俭新手,但非常感谢您的帮助。您知道您的答案甚至与您自己的问题不匹配吗?W