本文整理汇总了TypeScript中rcf.AuthorizedRestApi类的典型用法代码示例。如果您正苦于以下问题:TypeScript AuthorizedRestApi类的具体用法?TypeScript AuthorizedRestApi怎么用?TypeScript AuthorizedRestApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthorizedRestApi类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: Date
import * as rcf from 'rcf';
import * as $node from 'rest-node';
import * as fs from 'fs';
import * as path from 'path';
let configFile = (process.argv.length < 3 ? path.join(__dirname, '../client_test_config.json') : process.argv[2]);
let connectOptions: rcf.ApiInstanceConnectOptions = JSON.parse(fs.readFileSync(configFile, 'utf8'));
let pathname = '/services/events/event_stream';
let api = new rcf.AuthorizedRestApi($node.get(), rcf.AuthorizedRestApi.connectOptionsToAccess(connectOptions));
let clientOptions: rcf.IMessageClientOptions = {reconnetIntervalMS: 3000};
let client = api.$M(pathname, clientOptions);
client.on('connect', (conn_id:string) => {
console.log('');
console.log('connected: conn_id=' + conn_id);
console.log('');
//let topic = '/topic/'+conn_id;
let topic = '/topic/say_hi';
client.subscribe(topic
, (msg: rcf.IMessage): void => {
console.log('msg-rcvd:');
console.log('===============================================');
console.log(JSON.stringify(msg, null, 2));
console.log('===============================================');
}, {"selector": "location = 'USA'"}
).then((sub_id: string) => {
console.log('topic subscribed sub_id=' + sub_id + " :-)");
console.log('sending a test message...');
return client.send(topic, {'location': 'USA'}, {'greeting':'good afternoon ' + new Date()});
开发者ID:wchang28,项目名称:topic-eventsource,代码行数:31,代码来源:clientTest.ts
示例2: getDefaultNodeName
if (address.family === 'IPv4' && !address.internal) {
ipv4Addresses.push(address.address);
}
}
}
if (ipv4Addresses.length > 0) {
return ipv4Addresses[0];
} else { // no IPv4 address
return '{?}';
}
}
let dispatcherConfig = config.dispatcherConfig;
let pathname = '/node-app/events/event_stream';
let api = new rcf.AuthorizedRestApi($node.get(), rcf.AuthorizedRestApi.connectOptionsToAccess(dispatcherConfig));
let clientOptions: rcf.IMessageClientOptions = {reconnetIntervalMS: 10000};
let cpus = os.cpus();
let numCPUs:number = (config.numCPUs ? config.numCPUs : cpus.length - (config.reservedCPUs ? config.reservedCPUs : 2));
numCPUs = Math.max(numCPUs, 1);
let nodeName:string = (config.nodeName ? config.nodeName : getDefaultNodeName());
console.log(new Date().toISOString() + ': nodeName=' + nodeName + ', cpus=' + cpus.length + ', numCPUs=' + numCPUs);
let tasksTracker = new TasksTracker();
interface ITaskExec {
run(task: ITask) : Promise<void>;
on(event: "error", listener: (err: any) => void) : this;
on(event: "exec-params", listener: (taskExecParams: ITaskExecParams) => void) : this;
on(event: "started", listener: (pid: number) => void) : this;
开发者ID:wchang28,项目名称:node-grid-2,代码行数:31,代码来源:launcherApp.ts
示例3:
import * as $node from 'rest-node';
import * as FormData from 'form-data';
import * as rcf from 'rcf';
import * as fs from 'fs';
import * as path from 'path';
let configFile = (process.argv.length < 3 ? path.join(__dirname, '../client_test_config.json') : process.argv[2]);
let connectOptions: rcf.ApiInstanceConnectOptions = JSON.parse(fs.readFileSync(configFile, 'utf8'));
let $driver = $node.get();
let api = new rcf.AuthorizedRestApi($driver, rcf.AuthorizedRestApi.connectOptionsToAccess(connectOptions));
//let form = new FormData();
let form: FormData = $driver.createFormData();
form.append('FirstName', 'Wen');
form.append('LastName', 'Chang');
form.append("Myfile[]", fs.createReadStream('C:/tmp/signedcorrected 4506-T.pdf'), 'signedcorrected 4506-T.pdf');
form.append("Myfile[]", fs.createReadStream('C:/tmp/polaris.txt'), 'polaris.txt');
api.$F("POST", '/services/upload/file_upload', form)
.then((ret: rcf.RESTReturn) => {
console.log(JSON.stringify(ret, null, 2));
}).catch((err: any) => {
console.error("!!! Error: " + JSON.stringify(err));
});
api.$F("POST", '/services/upload/s3_upload', form)
.then((ret: rcf.RESTReturn) => {
console.log(JSON.stringify(ret, null, 2));
}).catch((err: any) => {
console.error("!!! Error: " + JSON.stringify(err));
开发者ID:wchang28,项目名称:topic-eventsource,代码行数:31,代码来源:test.ts
示例4: sendDispatcherNodeReady
}).on('connect', () => {
console.error(new Date().toISOString() + ': connected to the database :-)');
let client = api.$M(pathname, clientOptions);
function sendDispatcherNodeReady() : Promise<rcf.RESTReturn> {
console.log(new Date().toISOString() + ': sending a node-ready message...');
let nodeReady: INodeReady = {
numCPUs: numCPUs
,name: nodeName
};
let msg: GridMessage = {
type: 'node-ready'
,content: nodeReady
};
return client.send('/topic/dispatcher', {type: 'node-ready'}, msg);
}
function notifyDispatcherTaskComplete(task: ITask) : Promise<rcf.RESTReturn> {
let msg: GridMessage = {
type: 'task-complete'
,content: task
};
return client.send('/topic/dispatcher', {type: 'task-complete'}, msg);
}
function killProcessesTree(pids:number[]) {
for (let i in pids) {
let pid = pids[i];
treeKill(pid, 'SIGKILL');
}
}
function sendNodeQueryStatusResponse(response: NodeQueryStatusResponse) : Promise<rcf.RESTReturn> {
let msg: GridMessage = {
type: 'node-query-status'
,content: response
};
return client.send('/topic/dispatcher', {type: 'node-query-status'}, msg);
}
client.on('connect', (nodeId:string) : void => {
console.log(new Date().toISOString() + ': connected to the dispatcher: nodeId=' + nodeId);
client.subscribe('/topic/node/' + nodeId
,(msg: rcf.IMessage): void => {
console.log(new Date().toISOString() + ': msg-rcvd: ' + JSON.stringify(msg));
let gMsg: GridMessage = msg.body;
if (gMsg.type === 'launch-task') {
let task: ITask = gMsg.content;
let TrackingId = tasksTracker.beginTracking(task);
let taskExec = getTaskExec(nodeId, gridDB);
taskExec.on("error", (err: any) => {
console.error(new Date().toISOString() + ": !!! Error running task " + JSON.stringify(task) + ": " + JSON.stringify(err) + " :-(");
// TODO: sent error message to the server
}).on("exec-params", (taskExecParams: ITaskExecParams) => {
tasksTracker.updateTracking(TrackingId, {cmd: taskExecParams.cmd, envJSON: taskExecParams.envJSON});
console.log(new Date().toISOString() + ": running task " + JSON.stringify(task) + " with exec-params=\n" + JSON.stringify(taskExecParams, null, 2));
}).on("started", (pid: number) => {
tasksTracker.updateTracking(TrackingId, {pid});
console.log(new Date().toISOString() + ": task " + JSON.stringify(task) + " started with pid=" + pid);
}).on("finished", (retCode: number) => {
console.log(new Date().toISOString() + ": task " + JSON.stringify(task) + " finished with retCode=" + retCode);
}).run(task)
.then(() => {
tasksTracker.endTracking(TrackingId);
notifyDispatcherTaskComplete(task)
.then(() => {
console.log(new Date().toISOString() + ': <task-complete> notification for task ' + JSON.stringify(task) + ' successfully sent to the dispatcher :-)');
}).catch((err: any) => {
console.error(new Date().toISOString() + ': !!! Error sending <task-complete> notification for task '+ JSON.stringify(task) + ' to the dispatcher :-(');
});
});
} else if (gMsg.type === 'kill-processes-tree') {
let pids: number[] = gMsg.content;
killProcessesTree(pids);
} else if (gMsg.type === 'node-query-status') {
let request: NodeQueryStatusRequest = gMsg.content;
let response: NodeQueryStatusResponse = {
QueryId: request.QueryId
,Status: {
FreeMem: os.freemem()
,TotalMem: os.totalmem()
,UptimeSec: os.uptime()
,RunningTasks: tasksTracker.toJSON()
}
};
sendNodeQueryStatusResponse(response)
.then(() => {
}).catch((err: any) => {
console.error(new Date().toISOString() + ': !!! Error sending back <node-query-status> message: ' + JSON.stringify(err));
});
}
},{})
.then((sub_id: string) => {
console.log(new Date().toISOString() + ': topic subscribed sub_id=' + sub_id + " :-)");
sendDispatcherNodeReady()
.then(() => {
console.log(new Date().toISOString() + ': message sent successfully :-)');
}).catch((err: any) => {
console.error(new Date().toISOString() + ': !!! Error: message send failed');
//.........这里部分代码省略.........
开发者ID:wchang28,项目名称:node-grid-2,代码行数:101,代码来源:launcherApp.ts
注:本文中的rcf.AuthorizedRestApi类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论