]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | var thrift = require('thrift'), | |
20 | ttransport = require('thrift/transport'); | |
21 | ||
22 | var UserStorage = require('./gen-nodejs/UserStorage'), | |
23 | ttypes = require('./gen-nodejs/user_types'); | |
24 | ||
25 | var f_conn = thrift.createConnection('localhost', 9090), // default: framed | |
26 | f_client = thrift.createClient(UserStorage, f_conn); | |
27 | var b_conn = thrift.createConnection('localhost', 9091, {transport: ttransport.TBufferedTransport}), | |
28 | b_client = thrift.createClient(UserStorage, b_conn); | |
29 | var user1 = new ttypes.UserProfile({uid: 1, | |
30 | name: "Mark Slee", | |
31 | blurb: "I'll find something to put here."}); | |
32 | var user2 = new ttypes.UserProfile({uid: 2, | |
33 | name: "Satoshi Tagomori", | |
34 | blurb: "ok, let's test with buffered transport."}); | |
35 | ||
36 | f_conn.on('error', function(err) { | |
37 | console.error("framed:", err); | |
38 | }); | |
39 | ||
40 | f_client.store(user1, function(err, response) { | |
41 | if (err) { console.error(err); return; } | |
42 | ||
43 | console.log("stored:", user1.uid, " as ", user1.name); | |
44 | b_client.retrieve(user1.uid, function(err, responseUser) { | |
45 | if (err) { console.error(err); return; } | |
46 | console.log("retrieved:", responseUser.uid, " as ", responseUser.name); | |
47 | }); | |
48 | }); | |
49 | ||
50 | b_client.store(user2, function(err, response) { | |
51 | if (err) { console.error(err); return; } | |
52 | ||
53 | console.log("stored:", user2.uid, " as ", user2.name); | |
54 | f_client.retrieve(user2.uid, function(err, responseUser) { | |
55 | if (err) { console.error(err); return; } | |
56 | console.log("retrieved:", responseUser.uid, " as ", responseUser.name); | |
57 | }); | |
58 | }); |