(
void);
44 virtual int Run(
void);
62arg_desc->SetUsageContext(
64 "NetCacheAPI Sample");
66arg_desc->AddOptionalKey(
69 "Load-balanced service name",
72arg_desc->AddDefaultKey(
75 "The stream API to use",
78arg_desc->SetConstraint(
111cout <<
"\nPutData()/ReadData() example:"<< endl;
121 stringmessage(
"The quick brown fox jumps over a lazy dog.");
122 key= nc_api.
PutData(message.c_str(), message.size());
127 stringmessage(
"second message");
134 stringmessage(
"yet another message");
135nc_api.
PutData(
key, message.c_str(), message.size());
136cout <<
"Wrote: '"<< message <<
"' to blob: "<<
key<< endl;
141 while(
result.ReadLine(blob_info)) {
143cout << blob_info << endl;
153cout <<
"Read: '"<< message <<
"'"<< endl;
165cout <<
"\nPartRead() example:"<< endl;
175 stringmessage(
"Just pretend this is a really huge blob, ok?");
176 key= nc_api.
PutData(message.c_str(), message.size());
177cout <<
"Wrote: '"<< message <<
"' to blob: "<<
key<< endl;
188 for(
size_t offset= 0; remaining > 0; ) {
191 static const size_tkMaxReadSize = 10;
192 size_tpart_size =
min(remaining, kMaxReadSize);
197cout <<
"Read: '"<< part <<
"'"<< endl;
201remaining -= part_size;
215cout <<
"\nCreateOStream()/GetIStream() example:"<< endl;
217unique_ptr<CNetCacheAPI> nc_api_p;
220 if(
GetArgs()[
"service"]) {
222 GetArgs()[
"service"].AsString(),
"ncapi_sample"));
235unique_ptr<CNcbiOstream> os(nc_api_p->CreateOStream(
key,
237*os <<
"line one\n";
238*os <<
"line two\n";
239*os <<
"line three"<< endl;
240cout <<
"Wrote three lines to blob: "<<
key<< endl;
251unique_ptr<CNcbiIstream> is(nc_api_p->GetIStream(
key));
255cout <<
"Read word: '"<< message <<
"'"<< endl;
264unique_ptr<CNcbiIstream> is(nc_api_p->GetIStream(
key));
265cout <<
"Read buffer: '"<< is->rdbuf() <<
"'"<< endl;
277cout <<
"\nCompression example:"<< endl;
287 stringmessage(
"The quick brown fox jumps over a lazy dog.");
292cout <<
"Wrote: '"<< message <<
"' to blob: "<<
key<< endl;
302getline(is_zip, message);
303cout <<
"Read: '"<< message <<
"'"<< endl;
316cout <<
"\nIWriter()/IReader() example:"<< endl;
335 stringtext1(
"just chars."), text2(
"with a newline");
338cout <<
"Wrote '"<< text1
339<<
"' and '"<< text2 <<
"' to blob: "<<
key<< endl;
343 char data[] =
"abcdefghij1234567890!@#";
344writer->Write(
data, strlen(
data));
345cout <<
"Wrote: '"<<
data 346<<
"' to blob: "<<
key<< endl;
359unique_ptr<IReader> reader(nc_api.
GetReader(
key, &blob_size));
370is >> text1 >> text2;
371cout <<
"Read '"<< text1
372<<
"' and '"<< text2 <<
"' from blob:"<<
key<< endl;
378 static const Uint8kMyBufSize = 10;
379 charmy_buf[kMyBufSize + 1];
389my_buf[bytes_read] =
'\0';
392cout <<
"Read: '"<< my_buf <<
"'"<< endl;
Client API for NetCache server.
Note about the "buf_size" parameter for streams in this API.
virtual int Run(void)
Run the application.
void DemoIWriterIReader(void)
virtual void Init(void)
Initialize the application.
void DemoCompression(void)
void DemoPartialRead(void)
Writer-based output stream.
CZipStreamCompressor â zlib based compression stream processor.
CZipStreamDecompressor â zlib based decompression stream processor.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eString
An arbitrary string.
@ eConstraint
Constraint is not inverted (taken as is)
@ fOwnReader
Delete the reader.
@ fOwnWriter
Delete the writer.
#define NCBI_USER_THROW(message)
Throw a quick-and-dirty runtime exception of type 'CException' with the given error message and error...
#define nc_blob_ttl
Blob life span in seconds.
CNcbiOstream * CreateOStream(string &key, const CNamedParameterList *optional=NULL)
Create a stream object for sending data to a blob.
size_t GetBlobSize(const string &blob_id, const CNamedParameterList *optional=NULL)
Returns the size of the BLOB identified by the "key" parameter.
void ReadPart(const string &key, size_t offset, size_t part_size, string &buffer, const CNamedParameterList *optional=NULL)
Read a part of the blob pointed to by "key" and store its contents in "buffer".
CNetServerMultilineCmdOutput GetBlobInfo(const string &blob_id, const CNamedParameterList *optional=NULL)
Return a CNetServerMultilineCmdOutput object for reading meta information about the specified blob.
string PutData(const void *buf, size_t size, const CNamedParameterList *optional=NULL)
Put BLOB to server.
CNcbiIstream * GetIStream(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Create an istream object for reading blob data.
IReader * GetReader(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Get a pointer to the IReader interface to read blob contents.
void ReadData(const string &key, string &buffer, const CNamedParameterList *optional=NULL)
Read the blob pointed to by "key" and store its contents in "buffer".
uint64_t Uint8
8-byte (64-bit) unsigned integer
ERW_Result
Result codes for I/O operations.
@ eRW_Success
Everything is okay, I/O completed.
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
const struct ncbi::grid::netcache::search::fields::KEY key
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
static size_t read_size(CNcbiIstream &stream, const char *name)
Reader-writer based streams.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4