Exemplo n.º 1
0
bool CNCproxy::HasBlob(const string& key)
{
    if (m_NC) {
        return m_NC->HasBlob(key);
    }
    return m_IC->HasBlob(key, m_subkey);
}
Exemplo n.º 2
0
 SNetCacheServerAutomationObject(CAutomationProc* automation_proc,
         CNetCacheAPI nc_api, CNetServer::TInstance server) :
     SNetCacheServiceAutomationObject(automation_proc,
             nc_api.GetServer(server)),
     m_NetServer(server)
 {
 }
Exemplo n.º 3
0
void CNCproxy::Remove(const string& key)
{
    if (m_NC) {
        m_NC->Remove(key);
        return;
    }
    m_IC->Remove(key, m_version, m_subkey);
}
Exemplo n.º 4
0
IReader* CNCproxy::GetData(const string& key, size_t* blob_size)
{
    if (m_NC) {
        return m_NC->GetData(key, blob_size);
    }
    return  m_IC->GetReadStream(key,m_version,m_subkey,blob_size /*,
    CNetCacheAPI::eCaching_AppDefault*/);
}
Exemplo n.º 5
0
IEmbeddedStreamWriter* CNCproxy::PutData(string* key)
{
    if (m_NC) {
        return m_NC->PutData(key);
    }
    string gkey(*key);
    return m_IC->GetNetCacheWriter( gkey, m_version, m_subkey);
}
Exemplo n.º 6
0
 SNetCacheServiceAutomationObject(CAutomationProc* automation_proc,
         const CNetCacheAPI& nc_server) :
     SNetServiceAutomationObject(automation_proc,
             CNetService::eSingleServerService),
     m_NetCacheAPI(nc_server)
 {
     m_Service = m_NetCacheAPI.GetService();
 }
Exemplo n.º 7
0
void CNCproxy::SetCommunicationTimeout(unsigned int sec)
{
    STimeout to;
    to.sec = sec;
    to.usec = 0;
    if (m_NC) {
        m_NC->SetCommunicationTimeout(to);
    } else {
        m_IC->SetCommunicationTimeout(to);
    }
}
Exemplo n.º 8
0
SNetCacheServer::SNetCacheServer(CAutomationProc* automation_proc,
        CNetCacheAPI nc_api, CNetServer::TInstance server) :
    SNetCacheService(automation_proc, nc_api.GetServer(server),
            CNetService::eSingleServerService),
    m_NetServer(server)
{
    if (m_Service.IsLoadBalanced()) {
        NCBI_THROW(CAutomationException, eCommandProcessingError,
                "NetCacheServer constructor: "
                "'server_address' must be a host:port combination");
    }
}
Exemplo n.º 9
0
int CCgiSampleApplication::ProcessRequest(CCgiContext& ctx)
{
    // Parse, verify, and look at cmd-line and CGI parameters via "CArgs"
    // (optional)
    x_LookAtArgs();

    // Given "CGI context", get access to its "HTTP request" and
    // "HTTP response" sub-objects
    const CCgiRequest& request  = ctx.GetRequest();
    const CCgiCookies& cookies  = request.GetCookies();
    CCgiResponse&      response = ctx.GetResponse();
     
    const CCgiCookie* cookie = cookies.Find(kSessionId, "", "" );
    string message = "<EMPTY>";
    string session_id;
    if (cookie) {
        session_id = cookie->GetValue();
        m_NetCacheAPI.ReadData(session_id, message);
        if (!message.empty()) 
            message = "'" + message + "'";
        else
            message = "<EMPTY>";
    }

    bool is_message = false;
    string new_message = request.GetEntry("Message", &is_message);
    if ( is_message && !new_message.empty() ) {       
        auto_ptr<CNcbiOstream> os(m_NetCacheAPI.CreateOStream(session_id));
        *os << new_message;
        os.reset();
        CCgiCookies& rcookies = response.Cookies();
        rcookies.Add(kSessionId, session_id);
        new_message = "'" +  new_message + "'";
    } else 
        new_message = "<HAS NOT BEEN CHANGED>";

    // Create a HTML page (using template HTML file "cgi_sample.html")
    auto_ptr<CHTMLPage> page;
    try {
        page.reset(new CHTMLPage("Sample CGI with NetCache Session", m_HtmlTempl));
    } catch (exception& e) {
        ERR_POST("Failed to create Sample CGI HTML page: " << e.what());
        return 2;
    }

    // Register substitution for the template parameters <@MESSAGE@> and
    // <@SELF_URL@>
    try {
        CHTMLPlainText* text = new CHTMLPlainText(message);
        page->AddTagMap("MESSAGE", text);

        text = new CHTMLPlainText(new_message);
        page->AddTagMap("NEW_MESSAGE", text);

        CHTMLPlainText* self_url = new CHTMLPlainText(ctx.GetSelfURL());
        page->AddTagMap("SELF_URL", self_url);
    }
    catch (exception& e) {
        ERR_POST("Failed to populate Sample CGI HTML page: " << e.what());
        return 3;
    }

    // Compose and flush the resultant HTML page
    try {
        response.WriteHeader();
        page->Print(response.out(), CNCBINode::eHTML);
    } catch (exception& e) {
        ERR_POST("Failed to compose/send Sample CGI HTML page: " << e.what());
        return 4;
    }

    return 0;
}