@@ -90,7 +90,10 @@ void RecordResponse(const std::string &response_channel, const std::string &key,
90
90
91
91
} // namespace
92
92
93
- ResponsePublisher::ResponsePublisher () : m_db(" APPL_STATE_DB" , 0 )
93
+ ResponsePublisher::ResponsePublisher (bool buffered) :
94
+ m_db(std::make_unique<swss::DBConnector>(" APPL_STATE_DB" , 0 )),
95
+ m_pipe(std::make_unique<swss::RedisPipeline>(m_db.get())),
96
+ m_buffered(buffered)
94
97
{
95
98
}
96
99
@@ -107,17 +110,14 @@ void ResponsePublisher::publish(const std::string &table, const std::string &key
107
110
}
108
111
109
112
std::string response_channel = " APPL_DB_" + table + " _RESPONSE_CHANNEL" ;
110
- if (m_notifiers.find (table) == m_notifiers.end ())
111
- {
112
- m_notifiers[table] = std::make_unique<swss::NotificationProducer>(&m_db, response_channel);
113
- }
113
+ swss::NotificationProducer notificationProducer{m_pipe.get (), response_channel, m_buffered};
114
114
115
115
auto intent_attrs_copy = intent_attrs;
116
116
// Add error message as the first field-value-pair.
117
117
swss::FieldValueTuple err_str (" err_str" , PrependedComponent (status) + status.message ());
118
118
intent_attrs_copy.insert (intent_attrs_copy.begin (), err_str);
119
119
// Sends the response to the notification channel.
120
- m_notifiers[table]-> send (status.codeStr (), key, intent_attrs_copy);
120
+ notificationProducer. send (status.codeStr (), key, intent_attrs_copy);
121
121
RecordResponse (response_channel, key, intent_attrs_copy, status.codeStr ());
122
122
}
123
123
@@ -140,17 +140,14 @@ void ResponsePublisher::publish(const std::string &table, const std::string &key
140
140
void ResponsePublisher::writeToDB (const std::string &table, const std::string &key,
141
141
const std::vector<swss::FieldValueTuple> &values, const std::string &op, bool replace)
142
142
{
143
- if (m_tables.find (table) == m_tables.end ())
144
- {
145
- m_tables[table] = std::make_unique<swss::Table>(&m_db, table);
146
- }
143
+ swss::Table applStateTable{m_pipe.get (), table, m_buffered};
147
144
148
145
auto attrs = values;
149
146
if (op == SET_COMMAND)
150
147
{
151
148
if (replace)
152
149
{
153
- m_tables[table]-> del (key);
150
+ applStateTable. del (key);
154
151
}
155
152
if (!values.size ())
156
153
{
@@ -160,9 +157,9 @@ void ResponsePublisher::writeToDB(const std::string &table, const std::string &k
160
157
// Write to DB only if the key does not exist or non-NULL attributes are
161
158
// being written to the entry.
162
159
std::vector<swss::FieldValueTuple> fv;
163
- if (!m_tables[table]-> get (key, fv))
160
+ if (!applStateTable. get (key, fv))
164
161
{
165
- m_tables[table]-> set (key, attrs);
162
+ applStateTable. set (key, attrs);
166
163
RecordDBWrite (table, key, attrs, op);
167
164
return ;
168
165
}
@@ -179,13 +176,23 @@ void ResponsePublisher::writeToDB(const std::string &table, const std::string &k
179
176
}
180
177
if (attrs.size ())
181
178
{
182
- m_tables[table]-> set (key, attrs);
179
+ applStateTable. set (key, attrs);
183
180
RecordDBWrite (table, key, attrs, op);
184
181
}
185
182
}
186
183
else if (op == DEL_COMMAND)
187
184
{
188
- m_tables[table]-> del (key);
185
+ applStateTable. del (key);
189
186
RecordDBWrite (table, key, {}, op);
190
187
}
191
188
}
189
+
190
+ void ResponsePublisher::flush ()
191
+ {
192
+ m_pipe->flush ();
193
+ }
194
+
195
+ void ResponsePublisher::setBuffered (bool buffered)
196
+ {
197
+ m_buffered = buffered;
198
+ }
0 commit comments